API 参考
以 https://ai.moespark.dev 为根。OpenAI 兼容接口统一前缀 /v1。
鉴权
Authorization: Bearer sk-你的令牌
Content-Type: application/json
接口一览
| 方法 | 路径 | 说明 |
|---|---|---|
| POST | /v1/chat/completions | 对话补全(核心) |
| POST | /v1/completions | 文本补全 |
| POST | /v1/embeddings | 向量化 |
| POST | /v1/images/generations | 图像生成 |
| POST | /v1/audio/transcriptions | 语音转写 |
| POST | /v1/audio/speech | 文本转语音 |
| POST | /v1/moderations | 内容审核 |
| POST | /v1/rerank | 重排序 |
| GET | /v1/models | 模型列表 |
| POST | /v1/messages | Claude 协议对话 |
| POST | /v1beta/models/{model}:generateContent | Gemini 协议对话 |
/v1/chat/completions 请求结构
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
| model | string | 是 | 模型名 |
| messages | array | 是 | 消息列表,元素含 role、content |
| temperature | number | 否 | 0–2 |
| top_p | number | 否 | 核采样 |
| n | int | 否 | 生成候选数 |
| stream | bool | 否 | 是否流式 |
| stream_options | object | 否 | 如 {include_usage:true} 在流末尾附带用量 |
| max_tokens | int | 否 | 最大输出 token |
| stop | string|array | 否 | 停止序列 |
| tools / tool_choice | array/object | 否 | 函数调用 |
| response_format | object | 否 | 结构化输出 |
| user | string | 否 | 终端用户标识(风控/统计用) |
响应结构
{
"id": "chatcmpl-abc",
"object": "chat.completion",
"created": 1794370000,
"model": "gpt-4o-mini",
"choices": [{
"index": 0,
"message": {"role": "assistant", "content": "..."},
"finish_reason": "stop"
}],
"usage": {"prompt_tokens": 10, "completion_tokens": 20, "total_tokens": 30}
}
finish_reason 取值:stop(正常)、length(达到 max_tokens)、tool_calls(触发工具)、content_filter(被审核拦截)。
/v1/embeddings
curl https://ai.moespark.dev/v1/embeddings \
-H "Authorization: Bearer sk-你的令牌" \
-H "Content-Type: application/json" \
-d '{"model":"text-embedding-3-small","input":["第一段","第二段"]}'
返回 data[].embedding(浮点数组)与 usage。维度随模型而定。
流式数据格式
data: {"id":"...","choices":[{"delta":{"content":"你"}}]}
data: {"id":"...","choices":[{"delta":{"content":"好"}}]}
data: [DONE]
常用响应头 / 元信息
| 头 | 含义 |
|---|---|
| x-oneapi-request-id | 网关请求 ID,排障时提供给管理员 |
| x-new-api-version | 网关版本号 |
| retry-after | 限流时建议的重试等待秒数(若返回) |