Api
Create chat completion
Generate grounded responses using the Unii chat completion API
Endpoint
POST
/v1/chat/completionsAuthentication
Authenticate requests using a Bearer API key in the Authorization header: Authorization: Bearer <YOUR_API_KEY>
Request body
Send a JSON object with the following parameters:
| Parameter | Type | Description |
|---|---|---|
messages* | array | A list of conversation messages. Each message must include a role ( system, user, or assistant) and content. |
temperature | number | Controls randomness in the response. A higher value (e.g., 0.8) makes the output more creative, and a lower value (e.g., 0.2) makes it more deterministic. |
max_tokens | integer | The maximum number of tokens to generate in the response. |
Example request
curl -X POST https://api.unii.dev/v1/chat/completions \-H "Authorization: Bearer your_api_key" \-H "Content-Type: application/json" \-d '{ "messages": [ { "role": "user", "content": "What is the return policy window?" } ], "temperature": 0.7, "max_tokens": 1024}'Example response
200OK{"id": "chatcmpl-8j9dK2lF0Vx3M5yHmZp4Rq","object": "chat.completion","created": 1729480000,"model": "unii-latest","choices": [ { "index": 0, "message": { "role": "assistant", "content": "You can return items within 30 days of purchase. ..." }, "finish_reason": "stop" }],"usage": { "prompt_tokens": 45, "completion_tokens": 128, "total_tokens": 173}}Errors
The API returns standard HTTP status codes to indicate success or failure:
| Parameter | Type | Description |
|---|---|---|
400 Bad Request | error | The request body is malformed or contains invalid parameters. Check the error message for details about the missing or invalid field. |
401 Unauthorized | error | The API key is missing, invalid, or expired. Verify your Authorization header and ensure the key is active in the [Unii Console](/authentication). |
429 Too Many Requests | error | You have exceeded the rate limit for your account. Wait before retrying or contact support to discuss higher limits. |
500 Internal Server Error | error | An unexpected server error occurred. Retry the request after a brief delay. If the problem persists, contact support. |