Skip to content

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 providerMust bind this type of group
ClaudeName contains "Claude", "Flagship", or "Premium"
GPTName contains "GPT"
GeminiName contains "Gemini"
Domestic modelsName 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:

bash
pip install openai anthropic google-generativeai
  • openai — call GPT and domestic models
  • anthropic — call Claude
  • google-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

GroupModel ID
Smart Preferred Channelclaude-haiku-4-5
Official Premium Channelclaude-sonnet-4-6
Official Flagship Channelclaude-opus-4-6

GPT Series

GroupModel ID
GPT-Trial Channelgpt-5.4

Gemini Series

GroupModel ID
Gemini-Official Channelgemini-2.5-flash

Domestic Model Series

GroupModel ID
Qwen Trial Channelqwen-plus
GLM Official Channel (OpenAI interface)glm-5.1
Kimi Official Channelkimi-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:

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:

bash
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:

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:

bash
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:

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:

bash
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:

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:

bash
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:

json
{
  "model": "claude-sonnet-4-6",
  "max_tokens": 1024,
  "system": "You are a helpful assistant.",
  "messages": [
    {"role": "user", "content": "Hello"}
  ]
}

Response body:

json
{
  "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):

json
{
  "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:

json
{
  "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:

json
{
  "contents": [
    {"parts": [{"text": "Hello"}]}
  ],
  "generationConfig": {
    "maxOutputTokens": 1024,
    "temperature": 0.7
  }
}

Response body:

json
{
  "candidates": [
    {
      "content": {"parts": [{"text": "Hello! How can I help you?"}], "role": "model"},
      "finishReason": "STOP"
    }
  ],
  "usageMetadata": {"promptTokenCount": 3, "candidatesTokenCount": 15}
}

Supported Parameters

Claude Interface

ParameterTypeRequiredDescription
modelstringYesModel ID, see the list above
max_tokensintegerYesMax output tokens, recommended 512–8192
messagesarrayYesConversation history, [{"role":"user","content":"..."}]
systemstringNoSystem prompt
temperaturefloatNoRandomness, 0–1, default 1
top_pfloatNoNucleus sampling, 0–1
top_kintegerNoTop-K sampling
streamboolNoWhether to stream the response, default false
stop_sequencesarrayNoStop generation when these strings are encountered

GPT / Domestic Model Interface

chat.completions

ParameterTypeRequiredDescription
modelstringYesModel ID
messagesarrayYesConversation history, including role (system/user/assistant) and content
temperaturefloatNoRandomness, 0–2, default 1
max_tokensintegerNoMax output tokens
top_pfloatNoNucleus sampling
streamboolNoWhether to stream the response, default false
stopstring/arrayNoStop words
presence_penaltyfloatNoTopic diversity, -2–2
frequency_penaltyfloatNoRepetition penalty, -2–2
nintegerNoNumber of candidates to generate, default 1

responses (GPT only)

ParameterTypeRequiredDescription
modelstringYesModel ID
inputstringYesUser input text
streamboolMust be trueWithout it, you'll get empty content but still be charged
instructionsstringNoSystem prompt (equivalent to system)
max_output_tokensintegerNoMax output tokens
temperaturefloatNoRandomness

Gemini Interface

ParameterTypeRequiredDescription
contentsarrayYesConversation content, [{"parts":[{"text":"..."}]}]
generationConfig.maxOutputTokensintegerNoMax output tokens
generationConfig.temperaturefloatNoRandomness, 0–2
generationConfig.topPfloatNoNucleus sampling
generationConfig.topKintegerNoTop-K sampling
systemInstructionobjectNoSystem prompt, {"parts":[{"text":"..."}]}

Common Errors

ErrorCauseWhat to Do
401 UnauthorizedWrong KeyGo back to the console and confirm the Key was copied completely and hasn't expired
403 no group boundKey not bound to a groupSelect a group for the Key in the console
503 / 404Group does not match the SDKClaude SDK needs a Claude group; OpenAI responses needs a GPT group; chat.completions needs a domestic model or compatible group
429 Too Many RequestsUpstream momentarily at full capacityWait a few seconds and retry; if it persists, ask an administrator to scale up
Empty content returned but still chargedGPT missing stream=TrueAdd it and it'll work