创建文本补全
curl --request POST \
--url https://kaienapi.com/v1/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "gpt-3.5-turbo-instruct",
"prompt": "Write a tagline for an API platform"
}
'import requests
url = "https://kaienapi.com/v1/completions"
payload = {
"model": "gpt-3.5-turbo-instruct",
"prompt": "Write a tagline for an API platform"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({model: 'gpt-3.5-turbo-instruct', prompt: 'Write a tagline for an API platform'})
};
fetch('https://kaienapi.com/v1/completions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://kaienapi.com/v1/completions"
payload := strings.NewReader("{\n \"model\": \"gpt-3.5-turbo-instruct\",\n \"prompt\": \"Write a tagline for an API platform\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}{}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}OpenAI legacy Completions 兼容接口。
何时调用
仅保留给仍依赖旧 Completions 路径的 SDK 或历史代码。新项目优先使用 /v1/chat/completions 或 /v1/responses。
请求格式
使用 application/json。常见字段为 model、prompt、max_tokens、temperature 和 stream。
迁移说明
如果 prompt 里已经包含角色和上下文,迁移到 Chat Completions 时可拆成 system 与 user 消息;迁移到 Responses 时可放入 input。
POST
/
v1
/
completions
创建文本补全
curl --request POST \
--url https://kaienapi.com/v1/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "gpt-3.5-turbo-instruct",
"prompt": "Write a tagline for an API platform"
}
'import requests
url = "https://kaienapi.com/v1/completions"
payload = {
"model": "gpt-3.5-turbo-instruct",
"prompt": "Write a tagline for an API platform"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({model: 'gpt-3.5-turbo-instruct', prompt: 'Write a tagline for an API platform'})
};
fetch('https://kaienapi.com/v1/completions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://kaienapi.com/v1/completions"
payload := strings.NewReader("{\n \"model\": \"gpt-3.5-turbo-instruct\",\n \"prompt\": \"Write a tagline for an API platform\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}{}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}Authorizations
在请求头中传入:Authorization: Bearer sk-...
Body
application/json
Response
补全结果
The response is of type object.