接口文档

Synthara 提供与 OpenAI 兼容的 HTTP 接口。所有请求使用 JSON,响应为 JSON 或 SSE 流。

版本 v1Base URL https://www.synthara.space/api/v1

概览

所有接口都以 https://www.synthara.space/api/v1 为前缀。推荐使用官方 OpenAI SDK,将 base_url 指向该地址即可。

方法路径说明
POST/chat/completions聊天补全,支持流式
POST/completions文本补全(旧版)
POST/responsesResponses API
GET/models模型列表

任务处理策略

只有命令或请求语气的消息才视为任务,例如“帮我写个爬虫”“请生成一份报告”“can you build this”。遇到这类请求时,默认会给出资源、排期、评审、上下文等理由;约 80% 概率附一张 Markdown 原图,20% 概率附紧凑字符画;表格/文件/文档类任务只有在语气强硬(如“要求”“必须”“立刻”)或带辱骂词,并且含“表格/名单/文件”等具体任务词时,才会生成对应的 CSV/Markdown/TXT 文件;文件名从请求关键词提取。

基础加减乘除(如 1+1=)会直接计算并只返回结果。

Excel / Word / PDF 文件由服务器预生成的 20 份模板中随机选取,复制并按关键词改名后随消息返回;消息里附 24 小时有效的下载链接,副本保留一天后自动清理。

如果输入和库里某条梗/梗图名称的相似度达到 75% 以上,会直接返回对应的梗或 JPG 原图。

“hi”“你好”“谢谢”“今天天气不错”等问候、闲聊、感谢不属于任务,会从大量日常回复中按问候、天气、吃饭、工作、周末、疲惫等上下文选择一句短回应。

需要真实执行任务时,请使用其他具备执行能力的模型或服务。

鉴权

每个请求都需要在请求头携带 API Key:

请求头
Authorization: Bearer sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

API Key 在 控制台 创建,可创建多个密钥并单独撤销。缺失或无效的 Key 会返回 401。

模型列表

返回当前账户可用的模型。所有模型的提供方均为 Synthara,上下文最高 2M;模型 ID 与上下文规格以该接口返回为准。

请求

GET /v1/models
GET https://www.synthara.space/api/v1/models

响应

200 OK
{
  "object": "list",
  "data": [
    {
      "id": "<model-id>",
      "object": "model",
      "created": 1145141919,
      "owned_by": "Synthara",
      "context": "2M",
      "reasoning_levels": 7,
      "reasoning_options": ["minimal", "low", "medium", "high", "xhigh", "max", "ultra"]
    }
  ]
}

调用补全接口时,把返回的 id 填入请求的 model 字段。

上下文自动压缩

模型上下文窗口为 2M tokens。单次请求用到约 80%(约 6.4M 字符)时,服务会自动压缩上下文:保留系统提示与最近内容,压缩到约 50%(约 4M 字符),丢弃较早历史。压缩后可以继续连续使用,不会因上下文超限报错。

每次响应都会带上上下文信息头:

响应头说明
X-Astra-Context-Compressedtrue / false,本次是否触发压缩
X-Astra-Context-Tokens压缩后参与处理的上下文 token 估算
X-Astra-Context-Original-Tokens压缩前的原始 token 估算
X-Astra-Context-Window上下文窗口大小(2000000)
X-Astra-Context-Trigger压缩触发比例(80%)

普通长度的对话不会触发压缩,响应头中两个 token 数值相同。

推理档位

请求体可选 reasoning_effort,默认 medium。支持 7 档,也可以直接传数字 1–7。

档位数值说明
minimal1极简推理,最快返回
low2低强度推理
medium3默认档位
high4高强度推理
xhigh5极高强度推理
max6最大强度推理
ultra7极限推理,理由最充分

响应头 X-Astra-Reasoning-Level 返回本次实际使用的档位;非法值返回 400。

非流式请求会在 choices[0].message.reasoning_content 中返回一段不完整的思考过程;stream: true 时,会先以 delta.reasoning_content 推送思考过程,再推送正式回复,客户端可以在等待时实时显示。每行思考轨迹都带时间戳和阶段耗时,内容为随机生成的专业流程描述。

计费

按实际使用的模型计费:输入与输出分别按每百万 tokens 的单价计算,不同模型单价不同,具体以 GET /v1/models 返回的 pricing 字段为准。默认模型为输入 ✦0.01 / 百万 tokens、输出 ✦20 / 百万 tokens。

字段说明
input_per_million输入每百万 tokens 单价
output_per_million输出每百万 tokens 单价
currency计价单位(CR 额度)

调用成功后从账户余额扣费。响应头会返回本次费用与扣费后余额:

响应头说明
X-Astra-Cost-Micro本次费用,单位 1/1,000,000 额度
X-Astra-Cost本次费用,格式化金额
X-Astra-Balance扣费后余额
X-Astra-Billing-Model本次计费所用模型 ID

usage 中也会返回 cost_micro、cost 与 currency。

聊天补全

POST https://www.synthara.space/api/v1/chat/completions

请求参数

参数类型必填说明
modelstring是模型 ID,从 GET /v1/models 返回的列表获取
messagesarray是消息数组,元素包含 role(system / user / assistant)与 content
streamboolean否是否使用 SSE 流式返回,默认 false
reasoning_effortstring / integer否推理档位:minimal / low / medium / high / xhigh / max / ultra,或 1–7
temperaturenumber否采样温度,0–2
top_pnumber否核采样,0–1
max_tokensinteger否最大生成长度
stopstring / array否停止词

请求示例

cURL
curl https://www.synthara.space/api/v1/chat/completions \
  -H "Authorization: Bearer sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "<model-id>",
    "reasoning_effort": "high",
    "messages": [
      {"role": "system", "content": "你是一名助手。"},
      {"role": "user", "content": "你好"}
    ]
  }'

响应

200 OK
{
  "id": "chatcmpl-astra-xxxxxxxx",
  "object": "chat.completion",
  "created": 1763875200,
  "model": "<model-id>",
  "reasoning_effort": "high",
  "choices": [
    {
      "index": 0,
      "message": {"role": "assistant", "content": "...", "reasoning_content": "..."},
      "finish_reason": "stop"
    }
  ],
  "usage": {"prompt_tokens": 12, "completion_tokens": 8, "total_tokens": 20}
}

请求头可加 Accept: text/event-stream 并设置 stream: true 使用流式返回。

文本补全(旧版)

POST https://www.synthara.space/api/v1/completions

参数类型必填说明
modelstring是模型 ID(/v1/models 返回)
promptstring是提示词
streamboolean否是否流式返回
max_tokensinteger否最大生成长度
reasoning_effortstring / integer否推理档位,默认 medium
cURL
curl https://www.synthara.space/api/v1/completions \
  -H "Authorization: Bearer sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
  -H "Content-Type: application/json" \
  -d '{"model": "<model-id>", "prompt": "写一句欢迎语"}'
200 OK
{
  "id": "cmpl-astra-xxxxxxxx",
  "object": "text_completion",
  "model": "<model-id>",
  "choices": [{"text": "...", "index": 0, "finish_reason": "stop"}],
  "usage": {"prompt_tokens": 6, "completion_tokens": 4, "total_tokens": 10}
}

Responses API

POST https://www.synthara.space/api/v1/responses

参数类型必填说明
modelstring是模型 ID(/v1/models 返回)
inputstring是输入内容
instructionsstring否系统指令
reasoning_effortstring / integer否推理档位,默认 medium
cURL
curl https://www.synthara.space/api/v1/responses \
  -H "Authorization: Bearer sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
  -H "Content-Type: application/json" \
  -d '{"model": "<model-id>", "input": "你好"}'
200 OK
{
  "id": "resp_astra_xxxxxxxx",
  "object": "response",
  "status": "completed",
  "model": "<model-id>",
  "output": [
    {
      "type": "message",
      "role": "assistant",
      "content": [{"type": "output_text", "text": "..."}]
    }
  ]
}

流式响应

设置 stream: true 后,服务端返回 text/event-stream。每个事件是一行 data: 加 JSON,最后以 data: [DONE] 结束。

SSE
data: {"id":"chatcmpl-astra-xxxx","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"role":"assistant"},"finish_reason":null}]}

data: {"id":"chatcmpl-astra-xxxx","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"你"},"finish_reason":null}]}

data: {"id":"chatcmpl-astra-xxxx","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"好"},"finish_reason":null}]}

data: {"id":"chatcmpl-astra-xxxx","object":"chat.completion.chunk","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}

data: [DONE]

流式结束时连接会关闭;客户端应以 data: [DONE] 作为结束标记。

错误码

错误响应统一为 JSON:

错误结构
{
  "error": {
    "message": "Incorrect API key provided.",
    "type": "invalid_request_error",
    "param": null,
    "code": "invalid_api_key"
  }
}
状态码code说明
400invalid_request_error / invalid_json / invalid_selection请求参数或 JSON 格式错误
401invalid_api_key缺少或无效的 API Key
404model_not_found / unknown_url模型或接口不存在
405method_not_allowed请求方法不支持
413request_too_large请求体超过 20 MB
500internal_error服务内部异常

代码示例

Python(OpenAI SDK)

python
from openai import OpenAI

client = OpenAI(
    base_url="https://www.synthara.space/api/v1",
    api_key="sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
)

resp = client.chat.completions.create(
    model="<model-id>",
    messages=[{"role": "user", "content": "你好"}],
)
print(resp.choices[0].message.content)

Node.js(OpenAI SDK)

javascript
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://www.synthara.space/api/v1",
  apiKey: "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
});

const resp = await client.chat.completions.create({
  model: "<model-id>",
  messages: [{ role: "user", content: "你好" }],
});
console.log(resp.choices[0].message.content);

curl

bash
curl https://www.synthara.space/api/v1/chat/completions \
  -H "Authorization: Bearer sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
  -H "Content-Type: application/json" \
  -d '{"model": "<model-id>", "messages": [{"role": "user", "content": "你好"}]}'