跳转到主要内容
POST
/
v1
/
completions
Completions(旧版)
curl --request POST \
  --url https://openp.ai/v1/completions
import requests

url = "https://openp.ai/v1/completions"

response = requests.post(url)

print(response.text)
const options = {method: 'POST'};

fetch('https://openp.ai/v1/completions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));
<?php

$curl = curl_init();

curl_setopt_array($curl, [
CURLOPT_URL => "https://openp.ai/v1/completions",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
package main

import (
"fmt"
"net/http"
"io"
)

func main() {

url := "https://openp.ai/v1/completions"

req, _ := http.NewRequest("POST", url, nil)

res, _ := http.DefaultClient.Do(req)

defer res.Body.Close()
body, _ := io.ReadAll(res.Body)

fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.post("https://openp.ai/v1/completions")
.asString();
require 'uri'
require 'net/http'

url = URI("https://openp.ai/v1/completions")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)

response = http.request(request)
puts response.read_body
传统的文本补全接口,主要用于历史兼容。 新项目请使用 Chat Completions

请求

curl https://openp.ai/v1/completions \
  -H "Authorization: Bearer $OPENPAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-3.5-turbo-instruct",
    "prompt": "Once upon a time",
    "max_tokens": 64,
    "temperature": 0.7
  }'

主要参数

字段类型说明
modelstring模型 ID(gpt-3.5-turbo-instruct 等少数模型支持)
promptstring | array输入 prompt
max_tokensinteger最大输出
temperature / top_pnumber采样
ninteger候选数量
streambooleanSSE 流
stopstring | array停止序列
presence_penalty / frequency_penaltynumber惩罚
echoboolean在输出中包含 prompt
best_ofinteger服务端生成多个后挑最优
logprobsinteger返回 logprobs

响应

{
  "id": "cmpl-...",
  "object": "text_completion",
  "created": 1715750400,
  "model": "gpt-3.5-turbo-instruct",
  "choices": [
    {
      "text": ", there was a small castle...",
      "index": 0,
      "logprobs": null,
      "finish_reason": "length"
    }
  ],
  "usage": {"prompt_tokens": 4, "completion_tokens": 64, "total_tokens": 68}
}

与 Chat 的迁移

prompt 改成 messages 即可:
- "prompt": "Once upon a time"
+ "messages": [{"role": "user", "content": "Continue: Once upon a time"}]
并把模型 ID 换成 gpt-5.5 等。