对话API示例
POST
/v1/chat/completions
请求参数
Header 参数
Authorization
string
用户API key
默认值:
{{key}}
Body 参数application/json
model
string
模型
示例值:
gpt-3.5-turbo-16kgpt-4-turbo-previewgpt-4o
stream
boolean
流返回
默认值:
true
temperature
number
温度
>= 0<= 2
默认值:
1
示例值:
1
messages
array [object {2}]
必需
role
string
必需
示例值:
systemuserassistant
content
string
必需
示例值:
hi
示例
{
"model": "gpt-4o-mini",
"stream": true,
"messages": [
{
"role": "user",
"content": "hi"
}
]
}
示例代码
Shell
JavaScript
Java
Swift
Go
PHP
Python
HTTP
C
C#
Objective-C
Ruby
OCaml
Dart
R
请求示例请求示例
Shell
JavaScript
Java
Swift
curl --location --request POST 'https://agi.ylsap.com/tolinks/v1/chat/completions' \
--header 'Authorization;' \
--header 'Content-Type: application/json' \
--data-raw '{
"model": "gpt-4o-mini",
"stream": true,
"messages": [
{
"role": "user",
"content": "hi"
}
]
}'
返回响应
🟢200成功
application/json
Body
object {0}
示例
data: {"id":"chatcmpl-9POb2NzTJwLGPa7sOy1xnUyLLfDH9","object":"chat.completion.chunk","created":1715839776,"model":"gpt-3.5-turbo-16k-0613","system_fingerprint":null,"choices":[{"index":0,"delta":{"role":"assistant","content":""},"logprobs":null,"finish_reason":null}],"usage":null}
data: {"id":"chatcmpl-9POb2NzTJwLGPa7sOy1xnUyLLfDH9","object":"chat.completion.chunk","created":1715839776,"model":"gpt-3.5-turbo-16k-0613","system_fingerprint":null,"choices":[{"index":0,"delta":{"content":"Hello"},"logprobs":null,"finish_reason":null}],"usage":null}
data: {"id":"chatcmpl-9POb2NzTJwLGPa7sOy1xnUyLLfDH9","object":"chat.completion.chunk","created":1715839776,"model":"gpt-3.5-turbo-16k-0613","system_fingerprint":null,"choices":[{"index":0,"delta":{"content":"!"},"logprobs":null,"finish_reason":null}],"usage":null}
data: {"id":"chatcmpl-9POb2NzTJwLGPa7sOy1xnUyLLfDH9","object":"chat.completion.chunk","created":1715839776,"model":"gpt-3.5-turbo-16k-0613","system_fingerprint":null,"choices":[{"index":0,"delta":{"content":" How"},"logprobs":null,"finish_reason":null}],"usage":null}
data: {"id":"chatcmpl-9POb2NzTJwLGPa7sOy1xnUyLLfDH9","object":"chat.completion.chunk","created":1715839776,"model":"gpt-3.5-turbo-16k-0613","system_fingerprint":null,"choices":[{"index":0,"delta":{"content":" can"},"logprobs":null,"finish_reason":null}],"usage":null}
data: {"id":"chatcmpl-9POb2NzTJwLGPa7sOy1xnUyLLfDH9","object":"chat.completion.chunk","created":1715839776,"model":"gpt-3.5-turbo-16k-0613","system_fingerprint":null,"choices":[{"index":0,"delta":{"content":" I"},"logprobs":null,"finish_reason":null}],"usage":null}
data: {"id":"chatcmpl-9POb2NzTJwLGPa7sOy1xnUyLLfDH9","object":"chat.completion.chunk","created":1715839776,"model":"gpt-3.5-turbo-16k-0613","system_fingerprint":null,"choices":[{"index":0,"delta":{"content":" assist"},"logprobs":null,"finish_reason":null}],"usage":null}
data: {"id":"chatcmpl-9POb2NzTJwLGPa7sOy1xnUyLLfDH9","object":"chat.completion.chunk","created":1715839776,"model":"gpt-3.5-turbo-16k-0613","system_fingerprint":null,"choices":[{"index":0,"delta":{"content":" you"},"logprobs":null,"finish_reason":null}],"usage":null}
data: {"id":"chatcmpl-9POb2NzTJwLGPa7sOy1xnUyLLfDH9","object":"chat.completion.chunk","created":1715839776,"model":"gpt-3.5-turbo-16k-0613","system_fingerprint":null,"choices":[{"index":0,"delta":{"content":" today"},"logprobs":null,"finish_reason":null}],"usage":null}
data: {"id":"chatcmpl-9POb2NzTJwLGPa7sOy1xnUyLLfDH9","object":"chat.completion.chunk","created":1715839776,"model":"gpt-3.5-turbo-16k-0613","system_fingerprint":null,"choices":[{"index":0,"delta":{"content":"?"},"logprobs":null,"finish_reason":null}],"usage":null}
data: {"id":"chatcmpl-9POb2NzTJwLGPa7sOy1xnUyLLfDH9","object":"chat.completion.chunk","created":1715839776,"model":"gpt-3.5-turbo-16k-0613","system_fingerprint":null,"choices":[{"index":0,"delta":{},"logprobs":null,"finish_reason":"stop"}],"usage":null}
data: {"id":"chatcmpl-9POb2NzTJwLGPa7sOy1xnUyLLfDH9","object":"chat.completion.chunk","created":1715839776,"model":"gpt-3.5-turbo-16k-0613","system_fingerprint":null,"choices":[],"usage":{"prompt_tokens":8,"completion_tokens":9,"total_tokens":17}}
data: [DONE]
修改于 2024-08-04 05:16:28