快速开始
Mythos Gateway 同时提供 OpenAI 与 Anthropic 兼容接口。使用官方 SDK,只需修改 base_url 与 api_key。
| 协议 | Base URL | 接口 |
|---|---|---|
| OpenAI | https://mythoskey.com/v1 | POST /v1/chat/completions · POST /v1/responses · GET /v1/models |
| Anthropic | https://mythoskey.com | POST /v1/messages |
from openai import OpenAI client = OpenAI(base_url="https://mythoskey.com/v1", api_key="mgc-…") resp = client.chat.completions.create( model="mythos-fast", max_tokens=1024, temperature=0.7, messages=[ {"role": "system", "content": "你是一个简洁的助手。"}, {"role": "user", "content": "你好"}, ], ) print(resp.choices[0].message.content) print(resp.usage) # prompt_tokens / completion_tokens / total_tokens
import anthropic client = anthropic.Anthropic( base_url="https://mythoskey.com", # SDK 会自动拼接 /v1/messages api_key="mgc-…", ) msg = client.messages.create( model="mythos-fast", max_tokens=1024, system="你是一个简洁的助手。", messages=[{"role": "user", "content": "你好"}], ) print(msg.content[0].text, msg.usage)
curl https://mythoskey.com/v1/chat/completions \ -H "Authorization: Bearer $MYTHOS_API_KEY" \ -H "Content-Type: application/json" \ -d '{"model": "mythos-fast", "max_tokens": 512, "messages": [{"role": "user", "content": "hi"}]}'
认证与密钥
所有接口通过 API 密钥认证,密钥以 mgc- 开头。以下两种请求头任选其一:
Authorization: Bearer mgc-…
# 或(Anthropic 风格)
x-api-key: mgc-…- 平台只保存密钥的哈希值,创建后无法再次查看完整密钥;遗失请删除后重新创建。
- 每个密钥可单独设置:名称、累计消费额度、允许使用的模型;可随时禁用或删除,立即生效。
- 请勿在前端代码或公开仓库中暴露密钥,建议通过环境变量
MYTHOS_API_KEY读取。
模型列表
请求中的 model 参数使用下表中的模型名。价格单位:元 / 百万 tokens,实时价格以 模型市场为准。也可以调用 GET /v1/models。
| model | 名称 | 上下文 | 输入 | 输出 |
|---|---|---|---|---|
mythos-fast | mythos-fast | — | ¥1.00 – ¥13.00 | ¥3.33 – ¥68.00 |
mythos-glm-live | mythos-glm-live | — | ¥1.00 | ¥3.33 |
mythos-kimi-live | mythos-kimi-live | — | ¥13.00 | ¥68.00 |
curl https://mythoskey.com/v1/models -H "Authorization: Bearer $MYTHOS_API_KEY"OpenAI 兼容接口
POSThttps://mythoskey.com/v1/chat/completions
支持 messages(system / user / assistant / tool)、max_tokens、temperature、top_p、stop、stream、tools / tool_choice、图片输入(image_url)以及 reasoning_content 思考内容回传。响应的 usage 字段给出本次计费所用的 token 数。
from openai import OpenAI client = OpenAI(base_url="https://mythoskey.com/v1", api_key="mgc-…") resp = client.chat.completions.create( model="mythos-fast", max_tokens=1024, temperature=0.7, messages=[ {"role": "system", "content": "你是一个简洁的助手。"}, {"role": "user", "content": "你好"}, ], ) print(resp.choices[0].message.content) print(resp.usage) # prompt_tokens / completion_tokens / total_tokens
curl https://mythoskey.com/v1/chat/completions \ -H "Authorization: Bearer $MYTHOS_API_KEY" \ -H "Content-Type: application/json" \ -d '{"model": "mythos-fast", "max_tokens": 512, "messages": [{"role": "user", "content": "hi"}]}'
POSThttps://mythoskey.com/v1/responses — OpenAI Responses API 的常用子集(文本、流式、工具)。
Anthropic 兼容接口
POSThttps://mythoskey.com/v1/messages
与 Anthropic Messages API 一致:需要 anthropic-version 请求头;支持 system、tools、图片、thinking / redacted_thinking 块回传与流式事件(message_start … message_stop)。
import anthropic client = anthropic.Anthropic( base_url="https://mythoskey.com", # SDK 会自动拼接 /v1/messages api_key="mgc-…", ) msg = client.messages.create( model="mythos-fast", max_tokens=1024, system="你是一个简洁的助手。", messages=[{"role": "user", "content": "你好"}], ) print(msg.content[0].text, msg.usage)
curl https://mythoskey.com/v1/messages \ -H "x-api-key: $MYTHOS_API_KEY" \ -H "anthropic-version: 2023-06-01" \ -H "Content-Type: application/json" \ -d '{"model": "mythos-fast", "max_tokens": 512, "messages": [{"role": "user", "content": "hi"}]}'
流式调用
设置 stream: true 后以 Server-Sent Events 逐段返回。OpenAI 协议下,用量在 [DONE] 之前一个 choices 为空的 chunk 中返回;Anthropic 协议下在 message_delta 事件中返回。
from openai import OpenAI client = OpenAI(base_url="https://mythoskey.com/v1", api_key="mgc-…") stream = client.chat.completions.create( model="mythos-fast", max_tokens=1024, stream=True, stream_options={"include_usage": True}, messages=[{"role": "user", "content": "你好"}], ) for chunk in stream: if chunk.choices and chunk.choices[0].delta.content: print(chunk.choices[0].delta.content, end="", flush=True) if chunk.usage: # 最后一个 chunk 携带用量 print("\n", chunk.usage)
import anthropic client = anthropic.Anthropic(base_url="https://mythoskey.com", api_key="mgc-…") with client.messages.stream( model="mythos-fast", max_tokens=1024, messages=[{"role": "user", "content": "你好"}], ) as stream: for text in stream.text_stream: print(text, end="", flush=True)
curl -N https://mythoskey.com/v1/chat/completions \ -H "Authorization: Bearer $MYTHOS_API_KEY" \ -H "Content-Type: application/json" \ -d '{"model": "mythos-fast", "stream": true, "max_tokens": 256, "messages": [{"role": "user", "content": "hi"}]}'
data: {"id":"chatcmpl-…","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"你"}}]}
data: {"id":"chatcmpl-…","object":"chat.completion.chunk","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
data: {"id":"chatcmpl-…","object":"chat.completion.chunk","choices":[],"usage":{"prompt_tokens":9,"completion_tokens":21,"total_tokens":30}}
data: [DONE]工具调用与视觉
按 OpenAI tools 或 Anthropic tools 格式传入即可。网关会把请求路由到支持该能力的上游;若某模型的上游都不支持,返回 400 capability_not_supported。
resp = client.chat.completions.create(
model="mythos-fast",
max_tokens=1024,
tools=[{
"type": "function",
"function": {
"name": "get_weather",
"description": "查询城市天气",
"parameters": {"type": "object", "properties": {"city": {"type": "string"}}, "required": ["city"]},
},
}],
messages=[{"role": "user", "content": "上海今天天气如何?"}],
)
print(resp.choices[0].message.tool_calls)计费与余额
- 费用 = 输入 tokens × 输入单价 + 缓存命中 tokens × 缓存单价 + 输出 tokens × 输出单价(元 / 百万 tokens),精确到 0.000001 元。
- 调用前按最大输出预留额度(未传 max_tokens 时按 4096 tokens 预留),结束后按实际用量结算。建议总是传入 max_tokens,以便用较小余额发起请求。
- 未传 max_tokens 且余额不足以覆盖默认预留时,网关会把输出上限下调到余额可承担的长度(不低于 256),并通过 X-Mythos-Max-Tokens-Clamped 告知;更低时返回 402。
- 每次调用的费用可在控制台“用量与账单”中按 x-request-id 查询并导出 CSV。本页不以失败请求免费作为承诺。
响应头
| 响应头 | 说明 |
|---|---|
x-request-id | 本次调用的唯一编号,与控制台“用量明细”一一对应 |
X-Mythos-Max-Tokens-Clamped | 未传 max_tokens 且余额不足以预留默认输出时,实际使用的 max_tokens |
X-Mythos-Cost-Warning | 成本异常提示(如短时间内重复发送完全相同的请求) |
Retry-After | 429 时建议的重试等待秒数 |
错误码
错误响应遵循所用协议的格式(OpenAI 为 error 对象,Anthropic 为 type: error)。code 字段稳定,可用于程序判断:
{
"error": {
"message": "Insufficient balance for this request; top up your account.",
"type": "insufficient_quota",
"code": "insufficient_balance",
"param": null
}
}| HTTP | code | 含义与处理 |
|---|---|---|
400 | invalid_request | 请求体不是合法 JSON 或字段不合法 |
400 | missing_anthropic_version | /v1/messages 缺少 anthropic-version 请求头 |
400 | capability_not_supported | 该模型的上游都不支持图片输入或工具调用 |
400 | upstream_bad_request | 上游拒绝了请求(如参数超出模型限制) |
401 | missing_api_key | 未提供 API 密钥 |
401 | invalid_api_key | 密钥不存在、已删除,或账户已停用 |
401 | key_disabled | 密钥已被你在控制台禁用 |
402 | insufficient_balance | 可用余额不足以预留本次请求的最大费用 |
402 | key_quota_exceeded | 该密钥已达到设定的消费额度 |
403 | model_not_allowed | 该密钥未被授权使用此模型 |
403 | model_not_billable | 模型未开放或尚未定价 |
404 | model_not_found | 模型名称不存在 |
413 | request_too_large | 请求体过大 |
429 | rate_limit_exceeded | 超过每分钟请求数限制,按 Retry-After 重试 |
429 | concurrency_limit_exceeded | 同一密钥并发请求过多 |
502 | upstream_error | 所有上游都失败(已自动重试与切换),可稍后重试 |
503 | no_available_provider | 模型当前没有可用上游(熔断或维护中) |
500 | internal_error | 网关内部错误,请携带 x-request-id 联系支持 |
速率限制
默认每个密钥每分钟 60 次请求、最多 8 个并发请求。超出时返回 429 与 Retry-After。需要更高限额请联系我们。