Quickstart
Create an API key in your personal console, then keep it in a server-side environment variable. Never put the key in browser code.
Set environment variables
export MENGBI_ROUTER_API_KEY="sk-mengbi-xxxxxx"
export MENGBI_ROUTER_BASE_URL="https://router-api.mengbi-ai.net/v1"Notesk-mengbi-xxxxxx is only a placeholder. Replace it with your own personal key.
Your first OpenAI-compatible request
POST /v1/chat/completionscurl https://router-api.mengbi-ai.net/v1/chat/completions \
-H "Authorization: Bearer sk-mengbi-xxxxxx" \
-H "content-type: application/json" \
-d '{
"model": "gpt-5.6-sol",
"messages": [{"role": "user", "content": "你好"}]
}'from openai import OpenAI
client = OpenAI(
api_key="sk-mengbi-xxxxxx",
base_url="https://router-api.mengbi-ai.net/v1",
)
response = client.chat.completions.create(
model="gpt-5.6-sol",
messages=[{"role": "user", "content": "你好"}],
)
print(response.choices[0].message.content)Model list
Call models by ID. The model catalog shows currently available models with published prices; read the endpoint list before integrating.
Read available models
GET /v1/modelscurl https://router-api.mengbi-ai.net/v1/models \
-H "Authorization: Bearer sk-mengbi-xxxxxx"{
"object": "list",
"data": [
{"id": "gpt-5.6-sol", "object": "model", "owned_by": "mengbi"},
{"id": "claude-sonnet-5", "object": "model", "owned_by": "anthropic"}
]
}NoteAvailability, model IDs, and prices can change. Do not permanently cache the full model list on the client.
Anthropic native
Use the native Anthropic protocol for Claude models to preserve message structure, streaming events, and model capabilities.
Basic request
POST /v1/messagescurl https://router-api.mengbi-ai.net/v1/messages \
-H "x-api-key: sk-mengbi-xxxxxx" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{
"model": "claude-sonnet-5",
"max_tokens": 1024,
"messages": [{"role": "user", "content": "用一句话介绍你自己"}]
}'from anthropic import Anthropic
client = Anthropic(
api_key="sk-mengbi-xxxxxx",
base_url="https://router-api.mengbi-ai.net",
)
response = client.messages.create(
model="claude-sonnet-5",
max_tokens=1024,
messages=[{"role": "user", "content": "你好"}],
)
print(response.content[0].text)Streaming request
Add stream: true to the request body. The response uses text/event-stream; keep reading events instead of parsing it as one JSON document.
{
"model": "claude-sonnet-5",
"max_tokens": 1024,
"stream": true,
"messages": [{"role": "user", "content": "写一首五言绝句"}]
}NoteA common event sequence is message_start, content_block_delta, message_delta, and message_stop.
OpenAI-compatible
For the OpenAI SDK, Codex, and most clients that support Chat Completions.
Chat Completions
POST /v1/chat/completionscurl https://router-api.mengbi-ai.net/v1/chat/completions \
-H "Authorization: Bearer sk-mengbi-xxxxxx" \
-H "content-type: application/json" \
-d '{
"model": "gpt-5.6-sol",
"max_tokens": 1024,
"messages": [{"role": "user", "content": "Hello"}]
}'import OpenAI from 'openai'
const client = new OpenAI({
apiKey: process.env.MENGBI_ROUTER_API_KEY,
baseURL: 'https://router-api.mengbi-ai.net/v1',
})
const response = await client.chat.completions.create({
model: 'gpt-5.6-sol',
messages: [{ role: 'user', content: '你好' }],
})
console.log(response.choices[0].message.content)Streaming request
Add stream: true to the Chat Completions request. The response uses standard OpenAI SSE chunks and ends with data: [DONE].
{
"model": "gpt-5.6-sol",
"stream": true,
"messages": [{"role": "user", "content": "写一段介绍"}]
}Responses API
For applications already using the OpenAI Responses SDK. Currently intended for GPT models.
Basic request
POST /v1/responsescurl https://router-api.mengbi-ai.net/v1/responses \
-H "Authorization: Bearer sk-mengbi-xxxxxx" \
-H "content-type: application/json" \
-d '{
"model": "gpt-5.6-sol",
"input": "用一句话介绍你自己"
}'from openai import OpenAI
client = OpenAI(
api_key="sk-mengbi-xxxxxx",
base_url="https://router-api.mengbi-ai.net/v1",
)
response = client.responses.create(
model="gpt-5.6-sol",
input="用一句话介绍你自己",
)
print(response.output_text)NoteUse /v1/messages for Claude and the Gemini native format for Gemini. Sending an incompatible model to /v1/responses returns an error.
Fast mode
If the model catalog marks a model as supporting fast mode, add service_tier: fast to Chat Completions or Responses API requests. Confirm availability from the model catalog and response.
{
"model": "gpt-5.6-sol",
"input": "分析这个需求",
"service_tier": "fast"
}Gemini native
Gemini CLI and native Gemini SDKs can use the Gemini-style path and request body.
Generate content
POST /v1beta/models/{model}:generateContentcurl https://router-api.mengbi-ai.net/v1beta/models/gemini-3.6-flash:generateContent \
-H "Authorization: Bearer sk-mengbi-xxxxxx" \
-H "content-type: application/json" \
-d '{
"contents": [{
"role": "user",
"parts": [{"text": "用一句话介绍你自己"}]
}]
}'{
"candidates": [{
"content": {"role": "model", "parts": [{"text": "你好!"}]},
"finishReason": "STOP"
}],
"usageMetadata": {
"promptTokenCount": 12,
"candidatesTokenCount": 22
}
}Streaming and environment variables
Use streamGenerateContent with alt=sse for streaming. Different Gemini clients may use different field names for a custom Base URL.
curl "https://router-api.mengbi-ai.net/v1beta/models/gemini-3.6-flash:streamGenerateContent?alt=sse" \
-H "Authorization: Bearer sk-mengbi-xxxxxx" \
-H "content-type: application/json" \
-d '{"contents": [{"role": "user", "parts": [{"text": "你好"}]}]}'export GOOGLE_GEMINI_BASE_URL="https://router-api.mengbi-ai.net"
export GEMINI_API_KEY="sk-mengbi-xxxxxx"
export GEMINI_API_KEY_AUTH_MECHANISM="bearer"