logoUNLI

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/completions

Authentication

Include your API key in the Authorization header:

Authorization: Bearer YOUR_API_KEY

Example 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

ParameterTypeRequiredDefaultDescription
modelstringYesautoModel to use for completion. Use auto for automatic routing
messagesarrayYes-Array of message objects representing the conversation
streambooleanNofalseEnable streaming responses
temperaturenumberNo1.0Temperature 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/messages

Authentication & 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/json

Example 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

ParameterTypeRequiredDefaultDescription
modelstringYesunli-autoModel identifier to use. Use unli-auto for automatic routing
messagesarrayYes-Array of conversational input messages (user and assistant)
max_tokensintegerYes-The maximum number of tokens to generate before stopping
systemstring | arrayNo-System prompt specifying context and instructions
streambooleanNofalseEnable incremental streaming via Server-Sent Events
temperaturenumberNo1.0Randomness amount (0.0 to 1.0)
top_pnumberNo-Nucleus sampling probability cutoff (0.0 to 1.0)
top_kintegerNo-Sample from the top K options for each subsequent token
stop_sequencesstring[]No-Custom stop sequences
toolsarrayNo-Definitions of tools the model may use
tool_choiceobjectNo-Tool choice specification (auto, any, tool)
metadataobjectNo-Metadata object such as user_id

Supported Image Formats

FormatMedia TypeMax SizeNotes
JPEGimage/jpeg20MBRecommended for photos
PNGimage/png20MBGood for screenshots and UI
GIFimage/gif20MBStatic images
WebPimage/webp20MBModern web format

On this page