Chat Completions
Overview
This documentation provides instructions on how to use the Chat Completions API endpoint. The API allows you to generate chat completions based on provided messages and parameters.
Base URL
Endpoint
Authentication
The API uses Bearer Token authentication. You must include your API key in the Authorization
header of each request.
Replace YOUR_API_KEY
with your actual API key.
Request Format
The request should be sent as a POST request with a JSON body.
Headers
Content-Type: application/json
Authorization: Bearer YOUR_API_KEY
Body Parameters
model
string
Yes
The ID of the model to use for generating completions.
messages
array
Yes
An array of message objects representing the conversation history.
temperature
float
No
Controls randomness in the output. Higher values make the output more random, lower values make it more deterministic. Range: 0.0 to 1.0.
stream
boolean
No
If set to true
, the response will be streamed as it's generated. Default is false
.
Message Object
Each message in the messages
array should have the following structure:
role
string
The role of the message sender. Use "user" for user messages and "assistant" for AI responses.
content
string
The content of the message.
Example Request
Response Format
The API returns a JSON response with the generated completion.
Response Fields
id
string
A unique identifier for the completion.
object
string
The object type, always "chat.completion".
created
number
The Unix timestamp of when the completion was created.
model
string
The ID of the model used for the completion.
choices
array
An array containing the completion choices.
usage
object
An object containing token usage information.
Choice Object
index
number
The index of the choice.
message
object
An object containing the completion message.
finish_reason
string
The reason why the completion finished.
Message Object
role
string
The role of the message, always "assistant" for completions.
content
string
The content of the completion message.
Usage Object
prompt_tokens
number
The number of tokens in the prompt.
completion_tokens
number
The number of tokens in the completion.
total_tokens
number
The total number of tokens used.
Example Response
Error Responses
The API may return error responses in the following format:
Common error status codes:
400: Bad Request - Invalid input parameters
401: Unauthorized - Invalid or missing API key
500: Internal Server Error
Example cURL Request
Here's an example of how to make a request using cURL:
Replace YOUR_API_KEY
with your actual API key.
Support
If you encounter any issues or have questions about the API, please contact our support team at support@upchatty.com.
Last updated