通用开放接口文本 API
POST /v1/completions
POST
/v1/completionsLegacy 文本补全接口。
鉴权:Bearer Token
Content-Type:application/json
请求体
{ "model": "gpt-4o", "prompt": "Say this is a test", "max_tokens": 100, "temperature": 0.7, "stream": false}请求字段
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | 模型 ID |
prompt | string / array | 是 | 提示文本 |
max_tokens | integer | 否 | 最大输出 Token 数 |
temperature | number | 否 | 采样温度 |
top_p | number | 否 | 核采样 |
n | integer | 否 | 生成数量,默认 1 |
stream | boolean | 否 | 是否流式 |
stop | string / array | 否 | 停止序列 |
请求示例(curl)
非流式:
curl https://www.yunsell.com/v1/completions \ -H "Authorization: Bearer sk-xxx" \ -H "Content-Type: application/json" \ -d '{ "model": "gpt-4o", "prompt": "Say this is a test", "max_tokens": 100, "temperature": 0.7, "stream": false }'流式(SSE):
curl -N https://www.yunsell.com/v1/completions \ -H "Authorization: Bearer sk-xxx" \ -H "Content-Type: application/json" \ -d '{ "model": "gpt-4o", "prompt": "Say this is a test", "stream": true }'响应体(非流式)
HTTP 200
{ "id": "cmpl-abc123", "object": "text_completion", "created": 1712697600, "model": "gpt-4o", "choices": [ { "index": 0, "text": "This is indeed a test.", "finish_reason": "stop" } ], "usage": { "prompt_tokens": 5, "completion_tokens": 6, "total_tokens": 11 }}响应字段
| 字段 | 类型 | 说明 |
|---|---|---|
id | string | 响应 ID,如 cmpl-xxx |
object | string | 固定为 text_completion |
created | integer | Unix 时间戳(秒) |
model | string | 使用的模型 |
choices | array | 生成结果列表 |
choices[].index | integer | 结果索引 |
choices[].text | string | 补全文本 |
choices[].finish_reason | string | stop / length / content_filter |
usage | object | Token 用量,见 公共响应对象 |
响应体(流式)
data: {"id":"cmpl-abc123","object":"text_completion","created":1712697600,"choices":[{"index":0,"text":"This","finish_reason":null}]}data: {"id":"cmpl-abc123","object":"text_completion","created":1712697600,"choices":[{"index":0,"text":" is","finish_reason":null}]}data: [DONE]流式 chunk 字段
| 字段 | 类型 | 说明 |
|---|---|---|
id | string | 响应 ID |
object | string | 固定为 text_completion |
created | integer | Unix 时间戳(秒) |
choices[].index | integer | 结果索引 |
choices[].text | string | 增量文本片段 |
choices[].finish_reason | string / null | 末条 chunk 为结束原因 |