API guide
OpenAI-compatible API: change Base URL and Key to integrate. Routing and compliance stay on the platform; response headers record the actual upstream origin.
Overview
…/v1Point the OpenAI SDK base_url / baseURL here (same shape as https://api.openai.com/v1). Portal forwards /v1/* to the gateway.
Authorization: Bearer sk_live_…Replace the placeholder with a key from the Keys page; never commit plaintext keys. Keys
| Capability | LinkAI | Notes |
|---|---|---|
| Chat | POST /v1/chat/completions | OpenAI Chat Completions compatible |
| Image generation | POST /v1/images/generations | OpenAI Images; alias POST /v1/images. |
| Model list | GET /v1/models | Includes modality / pricing / compliance tags |
| Credits | GET /v1/credits | Platform extension |
| Usage | GET /v1/activity | Platform extension |
| Current key | GET /v1/key | Limits and usage snapshot |
Quickstart
Same as OpenRouter / OpenAI: create a key, then send a chat completion. Prefer the official OpenAI SDK and only change the base URL.
export LINKAI_API_KEY=$LINKAI_API_KEY
curl …/v1/chat/completions \
-H "Authorization: Bearer $LINKAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "linkai/deepseek-v4-pro",
"messages": [{"role": "user", "content": "Hello"}]
}'Streaming
Set stream: true for SSE (text/event-stream). Common pitfalls: proxy buffering or missing data: [DONE] — verify in the live debugger. Live debugger →
curl …/v1/chat/completions \
-H "Authorization: Bearer $LINKAI_API_KEY" \
-H "Content-Type: application/json" \
-N \
-d '{
"model": "linkai/deepseek-v4-pro",
"stream": true,
"messages": [{"role": "user", "content": "Introduce Hainan in three sentences"}]
}'Request parameters
| Field | Type | Notes |
|---|---|---|
| model | string | Platform model id; also auto / linkai/auto |
| messages | array | OpenAI messages; content may be string or multimodal parts |
| stream | boolean | Default false; true returns SSE |
| temperature | number | Sampling temperature when supported |
| max_tokens | number | Max generation tokens; also accepts max_completion_tokens |
| top_p | number | Nucleus sampling |
| tools / tool_choice | array / string|object | Tool calling; only models whose modality supports tools |
| reasoning | object | OpenRouter-style { effort, enabled, exclude }; translated to upstream thinking |
| reasoning_effort | string | Shorthand effort: none / low / high / max (medium→high) |
| include_reasoning | boolean | false may still bill reasoning tokens but omits reasoning text |
| thinking | object | DeepSeek-native { type: enabled|disabled }; use this or reasoning |
Whether a parameter is accepted follows the catalog supported_parameters / modality. Models
Reasoning
Reasoning-capable models (e.g. linkai/deepseek-v4-pro) use a unified reasoning object — no vendor-specific fields required.
- Enable: reasoning: { effort: "high" } or reasoning: { enabled: true }
- Disable: reasoning: { effort: "none" } or thinking: { type: "disabled" }
- Response content is the final answer; reasoning and reasoning_content are aliases for the chain-of-thought
curl …/v1/chat/completions \
-H "Authorization: Bearer $LINKAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "linkai/deepseek-v4-pro",
"messages": [{"role":"user","content":"9.11 和 9.8 哪个大?"}],
"reasoning": {"effort": "high"}
}'For multi-turn tool loops, echo the previous assistant reasoning_content in messages or some upstreams return HTTP 400. Reasoning and the final answer share max_tokens — too low yields HTTP 200 with empty content (use ≥4096).
Multimodal
Vision uses POST /v1/chat/completions with content parts text / image_url / input_audio / file. Pick models with image→text modality.
Image generation (e.g. Seedream) uses POST /v1/images/generations (or /v1/images), not chat. Pick text+image→image modality.
curl …/v1/images/generations \
-H "Authorization: Bearer $LINKAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "linkai/doubao-seedream-5.0-pro",
"prompt": "An ink-wash crane on a reef",
"size": "2K"
}'{
"model": "linkai/doubao-seed-vision",
"messages": [{
"role": "user",
"content": [
{"type": "text", "text": "Describe this image"},
{"type": "image_url", "image_url": {"url": "https://example.com/demo.png"}}
]
}]
}Models & auto
List models via GET /v1/models. A fixed model uses that SKU; auto uses the Portal routing pool / preference / smart routing. Routing
- Explicit: request a linkai/… id, bypass routing page
- Preference: model: "auto" + balance / price / latency preference
- Smart routing: when on, ignore the pool and pick site-wide (off by default)
Routing
Clients do not pick a vendor; the platform schedules by share and quality. Soft-prefer a source with a header (failover still applies):
curl …/v1/chat/completions \
-H "Authorization: Bearer $LINKAI_API_KEY" \
-H "X-LinkAI-Provider: deepseek" \
-H "Content-Type: application/json" \
-d '{"model":"linkai/deepseek-v4-pro","messages":[{"role":"user","content":"Hello"}]}'Optional X-LinkAI-Session for stickiness; X-LinkAI-Node-Id for exit node (advanced).
Response headers
The same headers are also accepted as X-TheSun2-*. X-LinkAI-* keeps working.
| Header | Meaning |
|---|---|
| X-LinkAI-Origin-Provider | Actual upstream provider (transparent origin) |
| X-LinkAI-Provider-Preferred-Hit | Whether preferred provider hit |
| X-LinkAI-Fallback | Whether failover occurred (1/0) |
| X-LinkAI-Exit-Gateway | Exit gateway (e.g. hainan) |
| X-LinkAI-Resource-Group | Hit resource group |
| X-LinkAI-Auto-Model | Resolved model after auto |
| X-LinkAI-Export-Control | Export-control block reason |
Error codes
Non-stream errors are JSON (OpenAI-style error.message / type / code). Common codes:
| HTTP | code | When |
|---|---|---|
| 401 | invalid_api_key | Missing or invalid Bearer key |
| 402 / 403 | insufficient_credits | Insufficient credits |
| 403 | firewall_blocked | Token firewall blocked |
| 403 | export_sanction_hit | Export-control gate |
| 400 | invalid_request | Unsupported modality / tools |
| 429 | rate_limit_exceeded | RPM / TPM exceeded |
| 502 / 504 | upstream_* | Upstream failure (may have failed over) |
Credits & limits
- Top up before calling; no free trial credits; insufficient balance rejects requests.
- Per-key RPM / TPM: see GET /v1/key and Keys detail.
- Account top-up and usage are available in the console. Credits · Activity
Stuck? Send a real request in the live debugger with the same key. Live debugger →