九章智算云
API 文档

Alaya Token兼提供 OpenAI 兼容接口和 Anthropic 兼容接口,支持主流 AI 应用无缝接入。

Base URL

https://token.alayanew.com

认证方式

所有 API 请求需要在 HTTP Header 中携带 API Key 进行认证:

Authorization: Bearer sk-your-api-key-here

你可以在 控制台 > 数据看板 页面查看使用情况和管理 API Key。

接口列表

POST /v1/chat/completions

创建聊天补全,支持流式和非流式响应。这是最常用的接口。

请求示例

curl https://token.alayanew.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-xxx" \
  -d '{
    "model": "glm-5.1",
    "messages": [
      {"role": "system", "content": "You are a helpful assistant"},
      {"role": "user", "content": "Hello"}
    ],
    "temperature": 0.7,
    "stream": false
  }'

响应示例

{
  "id": "chatcmpl-xxx",
  "object": "chat.completion",
  "created": 1234567890,
  "model": "glm-5.1",
  "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
  }
}

常用参数

参数类型说明
modelstring模型名称,如:glm-5.1glm-5.2
messagesarray对话消息列表
temperaturenumber温度参数,0-2,默认1
streamboolean是否启用流式响应,默认false
max_tokensinteger最大生成token数

POST /v1/responses

OpenAI Responses API,兼容 Codex CLI 等默认走 Responses 协议的客户端。请求用 input(字符串或 item 数组)+ instructions,响应为 response 对象(output[] + usage)。

请求示例

curl https://token.alayanew.com/v1/responses \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-xxx" \
  -d '{
    "model": "glm-5.2",
    "input": "Hello",
    "stream": false
  }'

响应示例

{
  "id": "resp_xxx",
  "object": "response",
  "status": "completed",
  "model": "glm-5.2",
  "output": [
    {
      "type": "message",
      "role": "assistant",
      "content": [{"type": "output_text", "text": "Hello! How can I help you?"}]
    }
  ],
  "usage": {"input_tokens": 9, "output_tokens": 12, "total_tokens": 21}
}

stream=true时返回 SSE 事件流(response.created / output_text.delta / completed 等)。无状态:不支持previous_response_id,多轮请重发完整input[]

GET /v1/models

列出当前可用的模型列表。

curl https://token.alayanew.com/v1/models \
  -H "Authorization: Bearer sk-xxx"

POST /anthropic/v1/messages

Anthropic Messages API 兼容接口。适用于 Claude Code 等使用 Anthropic SDK 的工具。

curl https://token.alayanew.com/anthropic/v1/messages \
  -H "Content-Type: application/json" \
  -H "x-api-key: sk-xxx" \
  -H "anthropic-version: 2023-06-01" \
  -d '{
    "model": "glm-5.1",
    "max_tokens": 1024,
    "messages": [
      {"role": "user", "content": "Hello"}
    ]
  }'

注意

Anthropic 兼容接口使用 x-api-key 头部而非 Authorization: Bearer

最后更新于

这篇文档对你有帮助吗?

目录