URI Endpoint for chat completion:
- POST
https://api.openai.com/v1/chat/completions
Headers:
Authorization: Bearer YOUR_API_KEY Content-Type: application/json
Request Structure:
{
"model": "gpt-4",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello, who won the world cup in 2018?"}
],
"temperature": 0.7
}
Response Structure:
{
"id": "chatcmpl-7vghhBnMywafj2w",
"object": "chat.completion",
"created": 1692987875,
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "France won the World Cup in 2018."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 35,
"completion_tokens": 7,
"total_tokens": 42
}
}