API Usage Guide
To connect gahorouter to any model SDK, you only need to change two parameters: api_key and base_url.
Requirement: Python ≥ 3.8
Table of Contents
- Get an API Key and bind a group
- Install the SDK
- Model list and rate multipliers
- API usage examples
- Request and response formats
- Supported parameters
- Common errors
Get an API Key and Bind a Group
Log in to https://console.gahorouter.com → "API Keys" → create a key, and you'll get cr-xxx...
In the "Group" column of the API key, click to select a group that matches the model you want to call:
| Calling this provider | Must bind this type of group |
|---|---|
| Claude | Name contains "Claude", "Flagship", or "Premium" |
| GPT | Name contains "GPT" |
| Gemini | Name contains "Gemini" |
| Domestic models | Name contains "DeepSeek / Qwen / GLM / Kimi / MiniMax", etc. |
Binding the wrong group will return 401/503; just go back to the console and reselect the group.
Install the SDK
Install only what you need, no need to install everything:
pip install openai anthropic google-generativeaiopenai— call GPT and domestic modelsanthropic— call Claudegoogle-generativeai— call Gemini
Model List and Rate Multipliers
The higher the multiplier, the more quota a single call consumes, and the stronger the corresponding capability.
To switch models, just modify the model field in each example.
Claude Series
| Group | Model ID |
|---|---|
| Smart Preferred Channel | claude-haiku-4-5 |
| Official Premium Channel | claude-sonnet-4-6 |
| Official Flagship Channel | claude-opus-4-6 |
GPT Series
| Group | Model ID |
|---|---|
| GPT-Trial Channel | gpt-5.4 |
Gemini Series
| Group | Model ID |
|---|---|
| Gemini-Official Channel | gemini-2.5-flash |
Domestic Model Series
| Group | Model ID |
|---|---|
| Qwen Trial Channel | qwen-plus |
| GLM Official Channel (OpenAI interface) | glm-5.1 |
| Kimi Official Channel | kimi-k2.5 |
| MiniMax Trial Channel (OpenAI interface) | MiniMax-M2.5 |
| DeepSeek Trial Channel (OpenAI interface) | deepseek-v3.2 |
API Usage Examples
Claude
Prerequisite: the Key is bound to a Claude group.
Python:
import anthropic
client = anthropic.Anthropic(
api_key="cr-xxxxxxxx",
base_url="https://console.gahorouter.com",
)
msg = client.messages.create(
model="claude-sonnet-4-6", # switch model: claude-opus-4-6 / claude-haiku-4-5-20251001
max_tokens=1024,
messages=[{"role": "user", "content": "Hello"}],
)
print(msg.content[0].text)curl:
curl https://console.gahorouter.com/v1/messages \
-H "x-api-key: cr-xxx" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-4-6",
"max_tokens": 1024,
"messages": [{"role": "user", "content": "Hello"}]
}'GPT
Prerequisite: the Key is bound to a GPT group. ⚠️ When using the responses interface, you must add stream=True.
Python:
from openai import OpenAI
client = OpenAI(
api_key="cr-xxxxxxxx",
base_url="https://console.gahorouter.com/v1",
)
stream = client.responses.create(
model="gpt-5.4", # switch model: gpt-4o / gpt-4o-mini / o3 / gpt-5.1-codex-max
input="Hello",
stream=True,
)
for ev in stream:
if ev.type == "response.output_text.delta":
print(ev.delta, end="", flush=True)curl:
curl -N https://console.gahorouter.com/v1/responses \
-H "Authorization: Bearer cr-xxx" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.4",
"input": "Hello",
"stream": true
}'Gemini
Prerequisite: the Key is bound to a Gemini group.
Python:
import google.generativeai as genai
genai.configure(
api_key="cr-xxxxxxxx",
client_options={"api_endpoint": "console.gahorouter.com"},
transport="rest",
)
model = genai.GenerativeModel("gemini-2.5-pro") # switch model: gemini-2.5-flash
print(model.generate_content("Hello").text)curl:
curl "https://console.gahorouter.com/v1beta/models/gemini-2.5-pro:generateContent" \
-H "x-goog-api-key: cr-xxx" \
-H "Content-Type: application/json" \
-d '{
"contents": [{"parts": [{"text": "Hello"}]}]
}'Domestic Models
Prerequisite: the Key is bound to the corresponding domestic model group.
Python:
from openai import OpenAI
client = OpenAI(
api_key="cr-xxxxxxxx",
base_url="https://console.gahorouter.com/v1",
)
resp = client.chat.completions.create(
model="deepseek-v3.2", # switch model: qwen-plus / glm-5.1 / kimi-k2.5 / MiniMax-M2.5
messages=[{"role": "user", "content": "Hello"}],
)
print(resp.choices[0].message.content)curl:
curl https://console.gahorouter.com/v1/chat/completions \
-H "Authorization: Bearer cr-xxx" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-v3.2",
"messages": [{"role": "user", "content": "Hello"}]
}'Request and Response Formats
Claude Format
Request body:
{
"model": "claude-sonnet-4-6",
"max_tokens": 1024,
"system": "You are a helpful assistant.",
"messages": [
{"role": "user", "content": "Hello"}
]
}Response body:
{
"id": "msg_01XFDUDYJgAACzvnptvVoYEL",
"type": "message",
"role": "assistant",
"content": [
{"type": "text", "text": "Hello! How can I help you?"}
],
"model": "claude-sonnet-4-6",
"stop_reason": "end_turn",
"usage": {"input_tokens": 10, "output_tokens": 25}
}GPT / Domestic Model Format
Request body (chat.completions):
{
"model": "deepseek-v3.2",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello"}
],
"temperature": 0.7,
"max_tokens": 1024,
"stream": false
}Response body:
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1700000000,
"model": "deepseek-v3.2",
"choices": [
{
"index": 0,
"message": {"role": "assistant", "content": "Hello! How can I help you?"},
"finish_reason": "stop"
}
],
"usage": {"prompt_tokens": 20, "completion_tokens": 15, "total_tokens": 35}
}Gemini Format
Request body:
{
"contents": [
{"parts": [{"text": "Hello"}]}
],
"generationConfig": {
"maxOutputTokens": 1024,
"temperature": 0.7
}
}Response body:
{
"candidates": [
{
"content": {"parts": [{"text": "Hello! How can I help you?"}], "role": "model"},
"finishReason": "STOP"
}
],
"usageMetadata": {"promptTokenCount": 3, "candidatesTokenCount": 15}
}Supported Parameters
Claude Interface
| Parameter | Type | Required | Description |
|---|---|---|---|
| model | string | Yes | Model ID, see the list above |
| max_tokens | integer | Yes | Max output tokens, recommended 512–8192 |
| messages | array | Yes | Conversation history, [{"role":"user","content":"..."}] |
| system | string | No | System prompt |
| temperature | float | No | Randomness, 0–1, default 1 |
| top_p | float | No | Nucleus sampling, 0–1 |
| top_k | integer | No | Top-K sampling |
| stream | bool | No | Whether to stream the response, default false |
| stop_sequences | array | No | Stop generation when these strings are encountered |
GPT / Domestic Model Interface
chat.completions
| Parameter | Type | Required | Description |
|---|---|---|---|
| model | string | Yes | Model ID |
| messages | array | Yes | Conversation history, including role (system/user/assistant) and content |
| temperature | float | No | Randomness, 0–2, default 1 |
| max_tokens | integer | No | Max output tokens |
| top_p | float | No | Nucleus sampling |
| stream | bool | No | Whether to stream the response, default false |
| stop | string/array | No | Stop words |
| presence_penalty | float | No | Topic diversity, -2–2 |
| frequency_penalty | float | No | Repetition penalty, -2–2 |
| n | integer | No | Number of candidates to generate, default 1 |
responses (GPT only)
| Parameter | Type | Required | Description |
|---|---|---|---|
| model | string | Yes | Model ID |
| input | string | Yes | User input text |
| stream | bool | Must be true | Without it, you'll get empty content but still be charged |
| instructions | string | No | System prompt (equivalent to system) |
| max_output_tokens | integer | No | Max output tokens |
| temperature | float | No | Randomness |
Gemini Interface
| Parameter | Type | Required | Description |
|---|---|---|---|
| contents | array | Yes | Conversation content, [{"parts":[{"text":"..."}]}] |
| generationConfig.maxOutputTokens | integer | No | Max output tokens |
| generationConfig.temperature | float | No | Randomness, 0–2 |
| generationConfig.topP | float | No | Nucleus sampling |
| generationConfig.topK | integer | No | Top-K sampling |
| systemInstruction | object | No | System prompt, {"parts":[{"text":"..."}]} |
Common Errors
| Error | Cause | What to Do |
|---|---|---|
| 401 Unauthorized | Wrong Key | Go back to the console and confirm the Key was copied completely and hasn't expired |
| 403 no group bound | Key not bound to a group | Select a group for the Key in the console |
| 503 / 404 | Group does not match the SDK | Claude SDK needs a Claude group; OpenAI responses needs a GPT group; chat.completions needs a domestic model or compatible group |
| 429 Too Many Requests | Upstream momentarily at full capacity | Wait a few seconds and retry; if it persists, ask an administrator to scale up |
| Empty content returned but still charged | GPT missing stream=True | Add it and it'll work |