Response Format
UNLI returns standardized responses based on the endpoint and format used.
OpenAI Format (/v1/chat/completions)
Standard Response
{
"choices": [
{
"finish_reason": "stop",
"index": 0,
"message": {
"content": "Hello! How can I help you today? 😊",
"padding": "abcdefghijklmnopqrstuvwxyz",
"role": "assistant"
}
}
],
"id": "chatcmpl-BsUWgXcLO95QZEJsoaLdtj9HHf9sj",
"usage": {
"completion_tokens": 11,
"prompt_tokens": 8,
"prompt_tokens_details": {
"cached_tokens": 0
},
"total_tokens": 19
},
"model": "auto",
"system_fingerprint": "fp_07e970ab25"
}Streaming Response
When stream: true, responses are sent as Server-Sent Events (SSE):
data: {"choices":[],"created":0,"id":""}
data: {"choices":[{"index":0,"delta":{"content":"","role":"assistant"}}],"created":1752331931,"id":"chatcmpl-BsVsBmSED2kGgzlZFq9xLxNSkE03L","model":"auto","system_fingerprint":"fp_07e970ab25"}
data: {"choices":[{"index":0,"delta":{"content":"Hello"}}],"created":1752331931,"id":"chatcmpl-BsVsBmSED2kGgzlZFq9xLxNSkE03L","model":"auto","system_fingerprint":"fp_07e970ab25"}
data: {"choices":[{"index":0,"delta":{"content":"!"}}],"created":1752331931,"id":"chatcmpl-BsVsBmSED2kGgzlZFq9xLxNSkE03L","model":"auto","system_fingerprint":"fp_07e970ab25"}
data: {"choices":[{"index":0,"delta":{"content":" How"}}],"created":1752331931,"id":"chatcmpl-BsVsBmSED2kGgzlZFq9xLxNSkE03L","model":"auto","system_fingerprint":"fp_07e970ab25"}
data: {"choices":[{"index":0,"delta":{"content":" can"}}],"created":1752331931,"id":"chatcmpl-BsVsBmSED2kGgzlZFq9xLxNSkE03L","model":"auto","system_fingerprint":"fp_07e970ab25"}
data: {"choices":[{"index":0,"delta":{"content":" I"}}],"created":1752331931,"id":"chatcmpl-BsVsBmSED2kGgzlZFq9xLxNSkE03L","model":"auto","system_fingerprint":"fp_07e970ab25"}
data: {"choices":[{"index":0,"delta":{"content":" help"}}],"created":1752331931,"id":"chatcmpl-BsVsBmSED2kGgzlZFq9xLxNSkE03L","model":"auto","system_fingerprint":"fp_07e970ab25"}
data: {"choices":[{"index":0,"delta":{"content":" you"}}],"created":1752331931,"id":"chatcmpl-BsVsBmSED2kGgzlZFq9xLxNSkE03L","model":"auto","system_fingerprint":"fp_07e970ab25"}
data: {"choices":[{"index":0,"delta":{"content":" today"}}],"created":1752331931,"id":"chatcmpl-BsVsBmSED2kGgzlZFq9xLxNSkE03L","model":"auto","system_fingerprint":"fp_07e970ab25"}
data: {"choices":[{"index":0,"delta":{"content":"?"}}],"created":1752331931,"id":"chatcmpl-BsVsBmSED2kGgzlZFq9xLxNSkE03L","model":"auto","system_fingerprint":"fp_07e970ab25"}
data: {"choices":[{"index":0,"delta":{"content":" 😊"}}],"created":1752331931,"id":"chatcmpl-BsVsBmSED2kGgzlZFq9xLxNSkE03L","model":"auto","system_fingerprint":"fp_07e970ab25"}
data: {"choices":[{"finish_reason":"stop","index":0,"delta":{"content":null}}],"created":1752331931,"id":"chatcmpl-BsVsBmSED2kGgzlZFq9xLxNSkE03L","usage":{"completion_tokens":11,"prompt_tokens":9,"total_tokens":20},"model":"auto","system_fingerprint":"fp_07e970ab25"}
data: [DONE]Anthropic Messages Format (/v1/messages)
Standard Response
{
"id": "msg_01XFDUDYJgAACgrFtApKcNx3",
"type": "message",
"role": "assistant",
"model": "unli-auto",
"content": [
{
"type": "text",
"text": "Hello! How can I assist you today?"
}
],
"stop_reason": "end_turn",
"stop_sequence": null,
"usage": {
"input_tokens": 10,
"output_tokens": 12
}
}Streaming Response (Anthropic SSE Events)
When stream: true, the API sends named events:
event: message_start
data: {"type":"message_start","message":{"id":"msg_01XFDUDYJgAACgrFtApKcNx3","type":"message","role":"assistant","content":[],"model":"unli-auto","stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":10,"output_tokens":1}}}
event: content_block_start
data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""}}
event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello"}}
event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"! How can I help you today?"}}
event: content_block_stop
data: {"type":"content_block_stop","index":0}
event: message_delta
data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"output_tokens":12}}
event: message_stop
data: {"type":"message_stop"}Error Responses
The API returns standard HTTP status codes and detailed error objects:
400 Bad Request
{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "Invalid request format or missing required fields"
}
}401 Unauthorized
{
"type": "error",
"error": {
"type": "authentication_error",
"message": "Invalid API key provided"
}
}429 Too Many Requests
{
"type": "error",
"error": {
"type": "rate_limit_error",
"message": "Rate limit exceeded. Please retry after some time."
}
}500 Internal Server Error
{
"type": "error",
"error": {
"type": "api_error",
"message": "An internal server error occurred"
}
}