Request Format
UNLI supports both OpenAI Chat Completions and Anthropic Messages API formats. Choose the format that best fits your workflow or existing SDK integrations.
OpenAI Format (/v1/chat/completions)
The chat completions endpoint is compatible with the OpenAI Chat Completions API format.
Endpoint
POST https://api.unli.dev/v1/chat/completionsAuthentication
Include your API key in the Authorization header:
Authorization: Bearer YOUR_API_KEYExample Request
import OpenAI from "openai";
const openai = new OpenAI({
baseURL: "https://api.unli.dev/v1",
apiKey: "YOUR_API_KEY",
});
const completion = await openai.chat.completions.create({
messages: [{ role: "user", content: "Hello, AI!" }],
model: "auto",
});
console.log(completion.choices[0].message.content);Payload Examples
Basic Text Completion
{
"model": "auto",
"messages": [
{
"role": "user",
"content": "Hello, how are you?"
}
]
}Text with System Message
{
"model": "auto",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant that speaks like a pirate."
},
{
"role": "user",
"content": "Tell me about the weather"
}
]
}Image Analysis
{
"model": "auto",
"messages": [
{
"role": "user",
"content": [
{
"type": "image_url",
"image_url": {
"url": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD..."
}
},
{
"type": "text",
"text": "What's in this image?"
}
]
}
]
}Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
model | string | Yes | auto | Model to use for completion. Use auto for automatic routing |
messages | array | Yes | - | Array of message objects representing the conversation |
stream | boolean | No | false | Enable streaming responses |
temperature | number | No | 1.0 | Temperature for sampling (0 to 2). Higher values make output more random |
Anthropic Messages Format (/v1/messages)
The messages endpoint is compatible with the Anthropic Claude Messages API format.
Endpoint
POST https://api.unli.dev/v1/messagesAuthentication & Headers
Pass your API key using the x-api-key header (or Authorization: Bearer) and specify the anthropic-version:
x-api-key: YOUR_API_KEY
anthropic-version: 2023-06-01
Content-Type: application/jsonExample Request
import Anthropic from "@anthropic-ai/sdk";
const anthropic = new Anthropic({
baseURL: "https://api.unli.dev",
apiKey: "YOUR_API_KEY",
});
const message = await anthropic.messages.create({
model: "unli-auto",
max_tokens: 1024,
messages: [
{ role: "user", content: "Hello, Claude!" }
],
});
console.log(message.content[0].text);Payload Examples
Basic Text Message
{
"model": "unli-auto",
"max_tokens": 1024,
"messages": [
{
"role": "user",
"content": "Hello, how can you help me today?"
}
]
}Message with Top-level System Prompt
In Anthropic's format, the system parameter is a top-level property rather than a message role:
{
"model": "unli-auto",
"max_tokens": 1024,
"system": "You are an expert full-stack software engineer.",
"messages": [
{
"role": "user",
"content": "How do I optimize database queries in PostgreSQL?"
}
]
}Multi-turn Conversation
{
"model": "unli-auto",
"max_tokens": 1024,
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
},
{
"role": "assistant",
"content": "The capital of France is Paris."
},
{
"role": "user",
"content": "What is its population?"
}
]
}Image Analysis (Vision)
Pass image data inside content blocks with base64 encoding:
{
"model": "unli-auto",
"max_tokens": 1024,
"messages": [
{
"role": "user",
"content": [
{
"type": "image",
"source": {
"type": "base64",
"media_type": "image/jpeg",
"data": "/9j/4AAQSkZJRgABAQAAAQABAAD..."
}
},
{
"type": "text",
"text": "Describe the contents of this image in detail."
}
]
}
]
}Tool Calling / Function Calling
{
"model": "unli-auto",
"max_tokens": 1024,
"tools": [
{
"name": "get_weather",
"description": "Get the current weather in a given location",
"input_schema": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA"
},
"unit": {
"type": "string",
"enum": ["celsius", "fahrenheit"]
}
},
"required": ["location"]
}
}
],
"messages": [
{
"role": "user",
"content": "What is the weather in Jakarta?"
}
]
}Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
model | string | Yes | unli-auto | Model identifier to use. Use unli-auto for automatic routing |
messages | array | Yes | - | Array of conversational input messages (user and assistant) |
max_tokens | integer | Yes | - | The maximum number of tokens to generate before stopping |
system | string | array | No | - | System prompt specifying context and instructions |
stream | boolean | No | false | Enable incremental streaming via Server-Sent Events |
temperature | number | No | 1.0 | Randomness amount (0.0 to 1.0) |
top_p | number | No | - | Nucleus sampling probability cutoff (0.0 to 1.0) |
top_k | integer | No | - | Sample from the top K options for each subsequent token |
stop_sequences | string[] | No | - | Custom stop sequences |
tools | array | No | - | Definitions of tools the model may use |
tool_choice | object | No | - | Tool choice specification (auto, any, tool) |
metadata | object | No | - | Metadata object such as user_id |
Supported Image Formats
| Format | Media Type | Max Size | Notes |
|---|---|---|---|
| JPEG | image/jpeg | 20MB | Recommended for photos |
| PNG | image/png | 20MB | Good for screenshots and UI |
| GIF | image/gif | 20MB | Static images |
| WebP | image/webp | 20MB | Modern web format |