> ## Documentation Index
> Fetch the complete documentation index at: https://docs.geeknow.top/llms.txt
> Use this file to discover all available pages before exploring further.

# 文本补全接口

> 使用 OpenAI Legacy Completions 兼容格式生成文本。

# 文本补全接口

Legacy Completions 接口使用 `prompt` 作为输入，适合仍在使用旧 OpenAI SDK 或简单补全文本的业务。新对话场景建议使用 [Chat Completions](./chat-completions-non-stream) 或 [OpenAI Responses](./openai-responses)。

<Warning>
  该接口只适合历史系统兼容，不建议新项目优先接入。模型列表中的聊天或推理模型不一定支持 Legacy Completions；上线前请单独验证目标模型。
</Warning>

## 请求体

<ParamField body="model" type="string" required>
  模型名称。
</ParamField>

<ParamField body="prompt" type="string | array<string>" required>
  输入提示词。
</ParamField>

<ParamField body="stream" type="boolean">
  是否启用流式输出。
</ParamField>

<ParamField body="max_tokens" type="integer">
  最大生成 token 数。
</ParamField>

<ParamField body="temperature" type="number">
  采样温度。
</ParamField>

<ParamField body="top_p" type="number">
  核采样参数。
</ParamField>

<ParamField body="stop" type="string | array<string>">
  停止序列。
</ParamField>

## 请求示例

<RequestExample>
  ```bash theme={null}
  curl -X POST https://www.geeknow.top/v1/completions \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "deepseek-v4-flash",
      "prompt": "把下面一句话改写得更正式：这个接口挺好用。",
      "max_tokens": 120,
      "temperature": 0.3
    }'
  ```
</RequestExample>

## 响应示例

<ResponseExample>
  ```json 200 theme={null}
  {
    "id": "cmpl_abc123",
    "object": "text_completion",
    "created": 1735689600,
    "model": "deepseek-v4-flash",
    "choices": [
      {
        "index": 0,
        "text": "该接口具备良好的易用性。",
        "finish_reason": "stop"
      }
    ],
    "usage": {
      "prompt_tokens": 22,
      "completion_tokens": 10,
      "total_tokens": 32
    }
  }
  ```

  ```json 400 theme={null}
  {
    "error": {
      "message": "field model is required",
      "type": "invalid_request_error",
      "param": "",
      "code": "invalid_request"
    }
  }
  ```

  ```json 401 theme={null}
  {
    "error": {
      "message": "Invalid API key provided",
      "type": "invalid_request_error",
      "param": "",
      "code": "invalid_api_key"
    }
  }
  ```

  ```json 402 theme={null}
  {
    "error": {
      "message": "用户额度不足",
      "type": "new_api_error",
      "param": "",
      "code": "insufficient_user_quota"
    }
  }
  ```

  ```json 429 theme={null}
  {
    "error": {
      "message": "当前请求频率过高，请稍后再试",
      "type": "new_api_error",
      "param": "",
      "code": "too_many_requests"
    }
  }
  ```

  ```json 500 theme={null}
  {
    "error": {
      "message": "bad response body",
      "type": "new_api_error",
      "param": "",
      "code": "bad_response_body"
    }
  }
  ```
</ResponseExample>

## 相关接口

* [Chat Completions（非流式）](./chat-completions-non-stream)
* [模型列表](./models)
