# AI Model API

- API version: 1.11.0
- Last updated: 2026-11-16
- Server: `https://api.ailingtu.com`
- Web document: [AI Model API](/en/openapi/ai-model-api)
- Full schema: [JSON Schema](/en/openapi/operations/createRelayChatCompletion.json)
- Discovery: [Operation index](/en/openapi/operations/index.json)

## POST /v1/relay/chat/completions

Operation ID: `createRelayChatCompletion`

Call supported LINGTU text and vision models through one OpenAI-compatible endpoint with JSON or SSE streaming responses.

Authentication: Request header `x-api-key: <YOUR_API_KEY>`; keep the key on the server and never expose it in client code, logs or shared files.

Success criteria: Read choices for non-streaming responses; concatenate choices[0].delta.content for streaming responses and stop after data: [DONE]; also check the HTTP status.

### Request parameters

| Field | Location | Type | Required | Description |
|---|---|---|---|---|
| `model` | body | string | Yes | Supported model identifier available to the current account |
| `messages` | body | RelayChatMessage[] | Yes | OpenAI-compatible messages with text and supported image_url content |
| `stream` | body | boolean | No | When true, returns incremental SSE content; defaults to false |
| `max_tokens` | body | integer | No | Maximum output tokens |
| `thinking.type` | body | enabled \| disabled | No | Enable or disable thinking when supported by the selected model |

Request format: `application/json`

### Stream events: Model output delta

```json
{
  "id": "chatcmpl_2066122904659169280",
  "model": "deepseek-v4-flash-vision-exp",
  "choices": [
    {
      "index": 0,
      "delta": {
        "content": "请求已"
      },
      "finish_reason": null
    }
  ]
}
```

### Response fields

Main levels are listed below. The endpoint JSON Schema is authoritative for the full structure, unions and validation rules; Required refers to the containing object.

| Field | Type | Required | Description |
|---|---|---|---|
| `id` | string | No | — |
| `model` | string | No | — |
| `choices` | object[] | Yes | — |
| `choices[].index` | integer | Yes | — |
| `choices[].message` | object | Yes | — |
| `choices[].message.role` | string | Yes | Fixed value: assistant |
| `choices[].message.content` | string | Yes | — |
| `choices[].finish_reason` | string \| null | No | — |
| `choices[].delta` | object | Yes | — |
| `choices[].delta.content` | string | No | — |

### Integration notes and limits

- Keep API keys on the server. Never place x-api-key in browser code, logs, or public files.
- With stream=true, parse each data: line and concatenate choices[0].delta.content until data: [DONE].
- Compute usage depends on the selected model, input content, output length, and multimodal inputs such as images.
- image_url must be reachable by the model service; choose an appropriate detail level for the task.

### Error handling

| HTTP | Description |
|---|---|
| 400 | The request parameters or body are invalid. Fix them and retry. |
| 401 | The API key is missing or invalid. Check x-api-key. |
| 403 | The API key has no permission to call this endpoint. |
| 429 | Too many requests. Retry with exponential backoff. |
| 500 | The server failed. Retry transient failures with exponential backoff. |

Treat any non-zero business code as a failure. Do not blindly retry parameter, permission or authorization errors. If creating a publishing or generation task times out, query the existing task first instead of creating another one.
