Skip to content
This page is a translation of the authoritative Chinese source and may lag behind.View the original

SDK Integration Overview

The gateway is a protocol-oriented entry point: whatever SDK you use on the client, as long as it speaks one of the gateway's supported protocols (OpenAI / Anthropic / Gemini / DashScope / Realtime / MCP / passthrough), pointing its base_url at the gateway and swapping its API key for a gateway-issued access key lets you call any model configured in the gateway — including cross-protocol calls to other vendors' models. This group of pages is organized by "which SDK you already have", each with a copy-paste minimal example.

The three universal steps

Every SDK follows the same wiring rule:

  1. Point base_url at the gateway (default http://localhost:7890). Note that each SDK differs on whether base_url includes /v1 — see the per-page examples.
  2. Set the API key to a gateway-issued access key, not an upstream sk-.... Access keys are issued on the Console's "Access keys" page.
  3. Set model to the model name configured in the gateway. The gateway does not restrict calls by model name — whatever name you configure in the console is what the client uses.

Model names that appear in examples (gpt-5.4-mini, claude-haiku-4-5, gemini-3.5-flash, qwen3.8-max, …) are just "real names under some gateway config"; use whatever your console defines.

Auth headers

Data-plane endpoints try the following auth methods in order, first match wins (see Endpoints · Auth):

HeaderCorresponding SDKNotes
Authorization: Bearer <access key>OpenAI, DashScope, genericBearer prefix is case-insensitive
x-api-key: <access key>Anthropic SDKAuthorization also accepted
x-goog-api-key: <access key>Gemini SDKAuthorization also accepted
(none of the above)Anonymous fallback, only if an anonymous=true key is configured

The three headers are just different mounting slots for the same "gateway access key" — issue one in the console and put it in whichever header your SDK expects.

SDK selection matrix

"I'm already using X — how do I connect it to the gateway?" Find your row:

SDK / frameworkLanguageProtocol / endpointTextImageVideoRealtimeEmbed/rerankPage
OpenAI SDKPy / Nodeopenai family (/v1/chat/completions, /v1/responses, …)✅¹Vendor SDKs
Anthropic SDKPy / Nodeanthropic (/v1/messages)input understandingVendor SDKs
Google GenAI SDKPy / JSgoogle (/v1beta/models/*)Vendor SDKs
DashScope SDK / HTTPPydashscope (/v1/services/*)✅ async✅¹DashScope native & async
OpenAI-compatible third parties (DeepSeek/GLM/Kimi/Grok…)Py / Nodeopenai compatiblevendor-dependentvendor-dependentVendor SDKs
Vercel AI SDKTSopenai / anthropic (provider layer)provider-dependentprovider-dependentUnified SDKs & gateways
LiteLLMPyopenai compatiblemodel-dependentUnified SDKs & gateways
LangChain / LangGraphPy / TSunderlying chat model (OpenAI/Anthropic…)model-dependentOrchestration frameworks
LlamaIndexPy / TSOpenAILike / chat modelmodel-dependentOrchestration frameworks
CrewAIPyunderlying LiteLLMmodel-dependentOrchestration frameworks
AutoGen / AG2Pyopenai compatiblemodel-dependentOrchestration frameworks
OpenAI Agents SDKPy / TSopenai_response (default)model-dependentAgent SDKs
Claude Agent SDKPy / TSanthropicinput understandingAgent SDKs
Pydantic AIPyopenai compatiblemodel-dependentAgent SDKs
Realtime (WebSocket)any WS clientopenai_realtime (/v1/realtime)Realtime & audio

¹ Realtime connects through the gateway's OpenAI Realtime client protocol (/v1/realtime) over a raw WebSocket — no vendor SDK is required; model is the realtime model's config name in the gateway (OpenAI or DashScope).

Cross-SDK pitfalls

No matter which SDK, after going through the gateway watch for these (each page repeats them; here they are in one place):

  • The model name must match the gateway config. The model you pass is "the name configured in the gateway" — not the vendor's official name, not the upstream's real model ID. Wrong name → 404 model_not_found.
  • Whether base_url includes /v1 varies by SDK. OpenAI SDK takes /v1; Anthropic SDK takes the root (it appends /v1/messages); Google GenAI takes the root (via http_options.base_url). Getting it wrong adds or drops a path segment.
  • Fields get translated and constrained by the target protocol across protocols. For example, if the gateway's gpt-5.6-sol upstream is a Responses protocol, a max_tokens passed by the client is translated to max_output_tokens, and the upstream may impose a lower bound (e.g. ≥16) — too small → 400.
  • Thinking blocks / signatures are wrapped by the gateway. Claude and Gemini thinking content (thinking / thoughtSignature) is passed through or stripped by the gateway; to get the text, take the type == "text" element of the content array — don't assume content[0] is text.
  • Third-party SDK model-name allowlists. Some frameworks (LlamaIndex, AutoGen, …) validate the model name against families they recognize and reject unknown gateway names — use their "any model" entry point or declare the model info explicitly (see each page).

Next