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

OpenAI-compatible Base URL (ends with /v1)
…/v1

Point the OpenAI SDK base_url / baseURL here (same shape as https://api.openai.com/v1). Portal forwards /v1/* to the gateway.

Auth
Header Authorization: Bearer sk_live_…

Replace the placeholder with a key from the Keys page; never commit plaintext keys. Keys

CapabilityLinkAINotes
ChatPOST /v1/chat/completionsOpenAI Chat Completions compatible
Image generationPOST /v1/images/generationsOpenAI Images; alias POST /v1/images.
Model listGET /v1/modelsIncludes modality / pricing / compliance tags
CreditsGET /v1/creditsPlatform extension
UsageGET /v1/activityPlatform extension
Current keyGET /v1/keyLimits 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

FieldTypeNotes
modelstringPlatform model id; also auto / linkai/auto
messagesarrayOpenAI messages; content may be string or multimodal parts
streambooleanDefault false; true returns SSE
temperaturenumberSampling temperature when supported
max_tokensnumberMax generation tokens; also accepts max_completion_tokens
top_pnumberNucleus sampling
tools / tool_choicearray / string|objectTool calling; only models whose modality supports tools
reasoningobjectOpenRouter-style { effort, enabled, exclude }; translated to upstream thinking
reasoning_effortstringShorthand effort: none / low / high / max (medium→high)
include_reasoningbooleanfalse may still bill reasoning tokens but omits reasoning text
thinkingobjectDeepSeek-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.

HeaderMeaning
X-LinkAI-Origin-ProviderActual upstream provider (transparent origin)
X-LinkAI-Provider-Preferred-HitWhether preferred provider hit
X-LinkAI-FallbackWhether failover occurred (1/0)
X-LinkAI-Exit-GatewayExit gateway (e.g. hainan)
X-LinkAI-Resource-GroupHit resource group
X-LinkAI-Auto-ModelResolved model after auto
X-LinkAI-Export-ControlExport-control block reason

Error codes

Non-stream errors are JSON (OpenAI-style error.message / type / code). Common codes:

HTTPcodeWhen
401invalid_api_keyMissing or invalid Bearer key
402 / 403insufficient_creditsInsufficient credits
403firewall_blockedToken firewall blocked
403export_sanction_hitExport-control gate
400invalid_requestUnsupported modality / tools
429rate_limit_exceededRPM / TPM exceeded
502 / 504upstream_*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 →