预生产环境 · 已配置真实支付服务商;支付操作可能产生真实资金变化。 价格配置尚未审批。

快速开始

Mythos Gateway 同时提供 OpenAI 与 Anthropic 兼容接口。使用官方 SDK,只需修改 base_url 与 api_key。

协议Base URL接口
OpenAIhttps://mythoskey.com/v1POST /v1/chat/completions · POST /v1/responses · GET /v1/models
Anthropichttps://mythoskey.comPOST /v1/messages
  1. 注册账户,在控制台 充值。
  2. 在 API 密钥 页面创建密钥(只显示一次,请立即保存)。
  3. 发起第一次调用:
Python · OpenAI SDK
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
Python · Anthropic SDK
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
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- 开头。以下两种请求头任选其一:

HTTP
Authorization: Bearer mgc-…
# 或(Anthropic 风格)
x-api-key: mgc-…
  • 平台只保存密钥的哈希值,创建后无法再次查看完整密钥;遗失请删除后重新创建。
  • 每个密钥可单独设置:名称、累计消费额度、允许使用的模型;可随时禁用或删除,立即生效。
  • 请勿在前端代码或公开仓库中暴露密钥,建议通过环境变量 MYTHOS_API_KEY 读取。

模型列表

请求中的 model 参数使用下表中的模型名。价格单位:元 / 百万 tokens,实时价格以 模型市场为准。也可以调用 GET /v1/models。

model名称上下文输入输出
mythos-fastmythos-fast—¥1.00 – ¥13.00¥3.33 – ¥68.00
mythos-glm-livemythos-glm-live—¥1.00¥3.33
mythos-kimi-livemythos-kimi-live—¥13.00¥68.00
curl
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 数。

Python
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
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)。

Python · Anthropic SDK
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
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 事件中返回。

Python · OpenAI
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)
Python · Anthropic
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
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"}]}'
SSE 响应示例
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。

Python
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-After429 时建议的重试等待秒数

错误码

错误响应遵循所用协议的格式(OpenAI 为 error 对象,Anthropic 为 type: error)。code 字段稳定,可用于程序判断:

HTTP 402
{
  "error": {
    "message": "Insufficient balance for this request; top up your account.",
    "type": "insufficient_quota",
    "code": "insufficient_balance",
    "param": null
  }
}
HTTPcode含义与处理
400invalid_request请求体不是合法 JSON 或字段不合法
400missing_anthropic_version/v1/messages 缺少 anthropic-version 请求头
400capability_not_supported该模型的上游都不支持图片输入或工具调用
400upstream_bad_request上游拒绝了请求(如参数超出模型限制)
401missing_api_key未提供 API 密钥
401invalid_api_key密钥不存在、已删除,或账户已停用
401key_disabled密钥已被你在控制台禁用
402insufficient_balance可用余额不足以预留本次请求的最大费用
402key_quota_exceeded该密钥已达到设定的消费额度
403model_not_allowed该密钥未被授权使用此模型
403model_not_billable模型未开放或尚未定价
404model_not_found模型名称不存在
413request_too_large请求体过大
429rate_limit_exceeded超过每分钟请求数限制,按 Retry-After 重试
429concurrency_limit_exceeded同一密钥并发请求过多
502upstream_error所有上游都失败(已自动重试与切换),可稍后重试
503no_available_provider模型当前没有可用上游(熔断或维护中)
500internal_error网关内部错误,请携带 x-request-id 联系支持

速率限制

默认每个密钥每分钟 60 次请求、最多 8 个并发请求。超出时返回 429 与 Retry-After。需要更高限额请联系我们。