Anthropic 兼容 API
为了满足大家对 vibe coding 等 AI 编程工具的需求,我们的 API 新增了对 Anthropic API 格式的兼容支持。通过简单的配置,即可将 ChatECNU 的能力,接入到 Anthropic API 生态中。
接入 Anthropic 生态工具
详见 Claude Code(Anthropic 终端工具)
通过 Anthropic API 调用 ChatECNU
- 安装
Anthropic SDK
pip install anthropic- 配置环境变量
export ANTHROPIC_BASE_URL=https://chat.ecnu.edu.cn/open/api/anthropic
export ANTHROPIC_AUTH_TOKEN=${your_api_key}- 调用
Anthropic API
import anthropic
client = anthropic.Anthropic()
message = client.messages.create(
model="ecnu-plus",
max_tokens=1000,
system="You are a helpful assistant.",
messages=[
{
"role": "user",
"content": [
{
"type": "text",
"text": "你好啊"
}
]
}
]
)
print(message.content)模型支持
我们的主力模型 ecnu-plus 与 ecnu-max 模型均支持 Anthropic API 格式的调用。
opus 系列模型会自动映射到 ecnu-max,sonnet 和 haiku 则映射至 ecnu-plus,
除此之外的模型请求,则会统一映射到 ecnu-plus 。
上下文长度
ecnu-max 模型当前支持最长 512K 的上下文输入,在 Anthropic 生态工具中直接将模型名配置为 ecnu-max 即可。部分工具(例如 Claude Code)无法识别 ecnu-max 的窗口大小,会按 200K 估算并提前压缩上下文,如需用满 512K,设置方法见 Claude Code。
早期为在 Anthropic 生态工具中使用 1M 上下文,需要在模型名后追加
[1m]后缀(如ecnu-max[1m]),该机制已不再适用,请直接使用ecnu-max。
思考强度支持
Anthropic Messages 兼容接口现已支持通过 output_config.effort 指定思考强度。由于不同协议定义的思考强度档位不同,代理服务会按模型完成档位映射:ecnu-max 支持 low / high / max,ecnu-plus 支持 low / medium / xhigh。
调用 ecnu-max 时:
| 客户端传入 | ecnu-max 实际档位 |
|---|---|
minimal | low |
low | low |
medium | high |
high | high |
xhigh | high |
max | max |
none | 关闭思考 |
调用 ecnu-plus 时:
| 客户端传入 | ecnu-plus 实际档位 |
|---|---|
minimal | low |
low | low |
medium | medium |
high | medium |
xhigh | xhigh |
max | xhigh |
none | 关闭思考 |
思考强度需开启思考模式后生效。传入
output_config.effort: "none"时,将关闭模型思考;未传入思考强度时,则继续使用服务端默认行为。完整配置示例与响应格式请参考 思考模式。
限流策略
您的请求将按 credits 配额统一处理,详见 配额限制,建议根据实际需求选择所需要的模型。