# Create Message

Create a model response using the Anthropic-compatible Messages format.

- Source: https://www.unifyllm.com/docs/api-reference/messages/
- Language: en
- Updated: 2026-11-30

## Endpoint

```http
POST https://api.unifyllm.top/v1/messages
```

Use the authentication and headers shown in the request examples. Content-Type: application/json

## Parameters

| Field | Location | Type | Required | Description | Allowed values | Example |
| --- | --- | --- | --- | --- | --- | --- |
| model | body | string | yes | Model identifier used for this request. |  |  |
| messages | body | array | yes | Messages that make up the conversation. |  |  |
| max_tokens | body | integer | yes | Maximum number of tokens allowed in the generated message. |  | 1024 |
| stream | body | boolean | no | Whether to stream partial results as they become available. |  |  |
| thinking | body | object | no | Extended thinking configuration for supported models. |  |  |

## Text

```json
{
  "model": "claude-sonnet-5",
  "max_tokens": 1024,
  "messages": [
    {
      "role": "user",
      "content": "hi"
    }
  ]
}
```

### cURL

```bash
curl --request POST \
  --url 'https://api.unifyllm.top/v1/messages' \
  --header 'Authorization: Bearer <YOUR_API_KEY>' \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "claude-sonnet-5",
  "max_tokens": 1024,
  "messages": [
    {
      "role": "user",
      "content": "hi"
    }
  ]
}'
```

### JavaScript

```javascript
const response = await fetch("https://api.unifyllm.top/v1/messages", {
  method: "POST",
  headers: {
    "Authorization": "Bearer <YOUR_API_KEY>",
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    "model": "claude-sonnet-5",
    "max_tokens": 1024,
    "messages": [
      {
        "role": "user",
        "content": "hi"
      }
    ]
  }),
});

const data = await response.json();
console.log(data);
```

### Python

```python
import json
import requests

response = requests.post(
    "https://api.unifyllm.top/v1/messages",
    headers={"Authorization": "Bearer <YOUR_API_KEY>"},
    json=json.loads("{\n  \"model\": \"claude-sonnet-5\",\n  \"max_tokens\": 1024,\n  \"messages\": [\n    {\n      \"role\": \"user\",\n      \"content\": \"hi\"\n    }\n  ]\n}")
)
response.raise_for_status()
print(response.json())
```

## Image Input

```json
{
  "model": "claude-sonnet-5",
  "max_tokens": 1024,
  "messages": [
    {
      "role": "user",
      "content": [
        {
          "type": "image",
          "source": {
            "type": "base64",
            "media_type": "image/jpeg",
            "data": "/9j/4AAQSkZJRg..."
          }
        },
        {
          "type": "text",
          "text": "What is in this image?"
        }
      ]
    }
  ]
}
```

### cURL

```bash
curl --request POST \
  --url 'https://api.unifyllm.top/v1/messages' \
  --header 'Authorization: Bearer <YOUR_API_KEY>' \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "claude-sonnet-5",
  "max_tokens": 1024,
  "messages": [
    {
      "role": "user",
      "content": [
        {
          "type": "image",
          "source": {
            "type": "base64",
            "media_type": "image/jpeg",
            "data": "/9j/4AAQSkZJRg..."
          }
        },
        {
          "type": "text",
          "text": "What is in this image?"
        }
      ]
    }
  ]
}'
```

### JavaScript

```javascript
const response = await fetch("https://api.unifyllm.top/v1/messages", {
  method: "POST",
  headers: {
    "Authorization": "Bearer <YOUR_API_KEY>",
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    "model": "claude-sonnet-5",
    "max_tokens": 1024,
    "messages": [
      {
        "role": "user",
        "content": [
          {
            "type": "image",
            "source": {
              "type": "base64",
              "media_type": "image/jpeg",
              "data": "/9j/4AAQSkZJRg..."
            }
          },
          {
            "type": "text",
            "text": "What is in this image?"
          }
        ]
      }
    ]
  }),
});

const data = await response.json();
console.log(data);
```

### Python

```python
import json
import requests

response = requests.post(
    "https://api.unifyllm.top/v1/messages",
    headers={"Authorization": "Bearer <YOUR_API_KEY>"},
    json=json.loads("{\n  \"model\": \"claude-sonnet-5\",\n  \"max_tokens\": 1024,\n  \"messages\": [\n    {\n      \"role\": \"user\",\n      \"content\": [\n        {\n          \"type\": \"image\",\n          \"source\": {\n            \"type\": \"base64\",\n            \"media_type\": \"image/jpeg\",\n            \"data\": \"/9j/4AAQSkZJRg...\"\n          }\n        },\n        {\n          \"type\": \"text\",\n          \"text\": \"What is in this image?\"\n        }\n      ]\n    }\n  ]\n}")
)
response.raise_for_status()
print(response.json())
```

## Response examples

### Default — HTTP 200

```json
{
  "content": [
    {
      "text": "Hi! How can I help you today?",
      "type": "text"
    }
  ],
  "id": "msg_011iQWcVm0bi7WY0htDBWQ6U",
  "model": "claude-sonnet-5",
  "role": "assistant",
  "stop_reason": "end_turn",
  "stop_sequence": null,
  "type": "message",
  "usage": {
    "cache_creation": {
      "ephemeral_1h_input_tokens": 0,
      "ephemeral_5m_input_tokens": 0
    },
    "cache_creation_input_tokens": 0,
    "cache_read_input_tokens": 157,
    "inference_geo": "not_available",
    "input_tokens": 54,
    "output_tokens": 11,
    "output_tokens_details": {
      "thinking_tokens": 0
    },
    "service_tier": "standard"
  }
}
```
