AI 模型接口补全(Completions)
原生 OpenAI 格式
OpenAI 文本补全接口(POST /v1/completions)。
接口说明
基于给定提示词创建文本补全(Legacy Completions API)。
端点
POST https://llm.inhabbit.com/v1/completions认证
| 参数 | 位置 | 类型 | 必需 | 说明 |
|---|---|---|---|---|
| Authorization | Header | string | 是 | 格式:Bearer sk-xxxxxx |
请求体(application/json)
| 参数 | 类型 | 必需 | 说明 |
|---|---|---|---|
| model | string | 是 | 模型标识 |
| prompt | string | array | 是 | 用于补全的文本提示词 |
| max_tokens | integer | 否 | 最大补全 Token 数 |
| temperature | number | 否 | 采样温度 |
| top_p | number | 否 | 核采样参数 |
| n | integer | 否 | 生成的补全数量 |
| stream | boolean | 否 | 是否启用流式响应 |
| stop | string | array | 否 | 停止序列 |
| suffix | string | 否 | 补全后的后缀文本 |
| echo | boolean | 否 | 是否在响应中回显提示词 |
响应(200 OK)
{
"id": "string",
"object": "text_completion",
"created": 0,
"model": "string",
"choices": [
{
"text": "string",
"index": 0,
"finish_reason": "string"
}
],
"usage": {
"prompt_tokens": 0,
"completion_tokens": 0,
"total_tokens": 0,
"prompt_tokens_details": {
"cached_tokens": 0,
"text_tokens": 0,
"audio_tokens": 0,
"image_tokens": 0
},
"completion_tokens_details": {
"text_tokens": 0,
"audio_tokens": 0,
"reasoning_tokens": 0
}
}
}响应字段说明
| 字段 | 类型 | 说明 |
|---|---|---|
| id | string | 补全的唯一标识 |
| object | string | 对象类型,固定为 text_completion |
| created | integer | 创建时间戳 |
| model | string | 使用的模型 |
| choices | array | 补全结果列表 |
| choices[].text | string | 生成的文本 |
| choices[].index | integer | 结果索引 |
| choices[].finish_reason | string | 完成原因 |
| usage | object | Token 使用统计 |
示例
curl -X POST "https://llm.inhabbit.com/v1/completions" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-xxxxxx" \
-d '{
"model": "gpt-3.5-turbo-instruct",
"prompt": "人工智能的未来是",
"max_tokens": 100,
"temperature": 0.7
}'