Keep your existing OpenAI SDK code — change one line and route to 50+ models.
The HuiLink gateway implements the OpenAI API protocol: same endpoints, same request/response shapes, same streaming format, and OpenAI-style errors. Point the official OpenAI SDK at our base URL and use your HuiLink API key.
Base URL
https://gateway.hkting.com/v1Install the official openai package, swap the base URL and API key — everything else stays the same.
curl https://gateway.hkting.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-your-huilink-key" \
-d '{
"model": "deepseek-v4-flash",
"messages": [{"role": "user", "content": "Hello!"}]
}'Tools and frameworks that read standard OpenAI env vars work without code changes.
# Shell — works with any tool that reads standard OpenAI env vars
export OPENAI_API_KEY="sk-your-huilink-key"
export OPENAI_BASE_URL="https://gateway.hkting.com/v1"
# No code changes at all — the official SDK picks these up automaticallyWhat happens to each OpenAI chat-completions parameter when it reaches the gateway.
| Parameter | Supported | Notes |
|---|---|---|
model | Required. Normalized to lowercase for routing and billing. | |
messages | String content and multimodal content arrays are both accepted. | |
stream | Server-sent events; terminated by a data: [DONE] frame. | |
temperature / top_p | Forwarded to the upstream provider. | |
max_tokens | Auto-raised to the model's minimum for reasoning models. | |
max_completion_tokens | Accepted and mapped to max_tokens. | |
stop / seed / user | Forwarded unchanged. | |
frequency_penalty / presence_penalty | Forwarded unchanged. | |
tools | Function definitions; availability depends on the target model. | |
tool_choice | "auto" | "none" | "required" | {type:"function",…}. | |
reasoning_effort | Passed to reasoning-capable models; ignored elsewhere. | |
n | Accepted but capped to 1 — only one completion is returned. | |
response_format | Silently ignored — not forwarded upstream. | |
logprobs / top_logprobs | Silently ignored. | |
stream_options | Silently ignored; the final chunk always carries usage. | |
parallel_tool_calls | Silently ignored. |
Beyond the OpenAI spec, an optional models array (OpenRouter-style) lists fallback models tried in order when the primary model has no healthy channel.
With "stream": true the gateway responds with standard OpenAI server-sent events — chat.completion.chunk frames and a data: [DONE] sentinel. Parse it with any OpenAI SDK or a plain SSE client.
data: {"id":"chatcmpl-…","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"Hel"}}]}
data: {"id":"chatcmpl-…","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"lo!"}}]}
data: {"id":"chatcmpl-…","object":"chat.completion.chunk","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
data: [DONE]Errors use the OpenAI envelope ({"error": {message, type, param, code}}), so existing error handling keeps working.
{
"error": {
"message": "model is required",
"type": "invalid_request_error",
"param": "model",
"code": null
}
}| HTTP | Meaning |
|---|---|
400 | Malformed request body or missing required field. |
401 | Invalid or revoked API key. |
402 | Insufficient balance — top up to continue. |
403 | Model blocked by this API key's model restrictions. |
404 | model_not_found — no pricing/channel serves this model. |
429 | Rate limit (RPM/TPM) or concurrency cap reached. |
500 | All channels for the model failed — retry with backoff. |
502 | Upstream provider error after failover was exhausted. |
The gateway also speaks two more protocols on the same key and billing.
/v1/responsesOpenAI Responses API — stateful, tool-native generation endpoint with the same model routing.
/v1/messagesAnthropic Messages API (plus /v1/messages/count_tokens) — run Claude-protocol clients against gateway models.