# Features of Anthropic Models

## Overview

Models from Anthropic can be accessed not only via the standard `/v1/chat/completions` endpoint but also through dedicated endpoints — `/messages` and `/v1/batches` and `/v1/batches/cancel/{batch_id}`.\
The sections below describe their API schemas, usage specifics, and example requests.

Supported capabilities:

* **Text completions:** Build advanced chat bots or text processors.
* **Function Calling:** Utilize tools for specific tasks and API calling.
* **Stream mode:** Get the text chat model responses as they are generated, rather than waiting for the entire response to be completed.
* **Batch Processing:** Send multiple independent requests in a single API call.
* **Vision Tasks:** Process and analyze images.

## Text Completions

Ask something and get an answer in a chat-like conversation format.

## POST /messages

>

```json
{"openapi":"3.0.0","info":{"title":"AI/ML Gateway","version":"1.0"},"servers":[{"url":"https://api.aimlapi.com"}],"security":[{"access-token":[]}],"components":{"securitySchemes":{"access-token":{"scheme":"bearer","bearerFormat":"<YOUR_AIMLAPI_KEY>","type":"http","description":"Bearer key"}},"schemas":{"LlmThreadMessage.v1.CreateMessageDTO":{"type":"object","properties":{"model":{"type":"string","enum":["claude-3-haiku-20240307","claude-sonnet-4-20250514","claude-opus-4-20250514","claude-opus-4-1-20250805","claude-sonnet-4-5-20250929","claude-haiku-4-5-20251001","claude-opus-4-5-20251101","claude-opus-4-6","claude-opus-4-7","claude-sonnet-4-6","anthropic/claude-3-haiku-20240307","anthropic/claude-3-haiku","claude-3-haiku-latest","anthropic/claude-sonnet-4","anthropic/claude-sonnet-4-20250514","claude-sonnet-4-latest","anthropic/claude-opus-4","anthropic/claude-opus-4-20250514","claude-opus-4-latest","claude-opus-4-1","anthropic/claude-opus-4.1","anthropic/claude-sonnet-4.5","claude-sonnet-4-5","anthropic/claude-haiku-4.5","claude-haiku-4-5","anthropic/claude-opus-4-5","anthropic/claude-opus-4.5","claude-opus-4-5","anthropic/claude-opus-4-6","anthropic/claude-sonnet-4.6","anthropic/claude-sonnet-4-6","anthropic/claude-sonnet-4-6-20260218","claude-sonnet-4-6-latest","anthropic/claude-opus-4.7"]},"messages":{"type":"array","items":{"type":"object","properties":{"role":{"type":"string","enum":["user","assistant"]},"content":{"anyOf":[{"type":"string"},{"type":"array","items":{"oneOf":[{"type":"object","properties":{"type":{"type":"string","enum":["text"]},"text":{"type":"string"}},"required":["type","text"],"additionalProperties":false},{"type":"object","properties":{"type":{"type":"string","enum":["image"]},"source":{"type":"object","properties":{"type":{"type":"string","enum":["base64"]},"media_type":{"type":"string","enum":["image/jpeg","image/png","image/gif","image/webp"]},"data":{"type":"string"}},"required":["type","media_type","data"]}},"required":["type","source"],"additionalProperties":false},{"type":"object","properties":{"type":{"type":"string","enum":["thinking"]},"thinking":{"type":"string"},"signature":{"type":"string"}},"required":["type","thinking","signature"],"additionalProperties":false},{"type":"object","properties":{"type":{"type":"string","enum":["tool_result"]},"tool_use_id":{"type":"string"},"is_error":{"type":"boolean"},"content":{"anyOf":[{"type":"string"},{"type":"array","items":{"oneOf":[{"type":"object","properties":{"type":{"type":"string","enum":["text"]},"text":{"type":"string"}},"required":["type","text"],"additionalProperties":false},{"type":"object","properties":{"type":{"type":"string","enum":["image"]},"source":{"type":"object","properties":{"type":{"type":"string","enum":["base64"]},"media_type":{"type":"string","enum":["image/jpeg","image/png","image/gif","image/webp"]},"data":{"type":"string"}},"required":["type","media_type","data"]}},"required":["type","source"],"additionalProperties":false}]}}]}},"required":["type","tool_use_id"]},{"type":"object","properties":{"id":{"type":"string"},"input":{"type":"object","additionalProperties":{"nullable":true}},"name":{"type":"string"},"type":{"type":"string","enum":["tool_use"]}},"required":["id","input","name","type"]},{"type":"object","properties":{"type":{"type":"string","enum":["redacted_thinking"]},"data":{"type":"string"}},"required":["type","data"]}]},"maxItems":5}]}},"required":["role","content"],"additionalProperties":false},"description":"A list of messages comprising the conversation so far. Depending on the model you use, different message types (modalities) are supported, like text, documents (txt, pdf), images, and audio."},"max_tokens":{"type":"number","minimum":1,"default":1024,"description":"The maximum number of tokens that can be generated in the chat completion. This value can be used to control costs for text generated via API."},"metadata":{"type":"object","additionalProperties":{"type":"string"},"description":"An object describing metadata about the request"},"stop_sequences":{"type":"array","items":{"type":"string"},"description":"Custom text sequences that will cause the model to stop generating."},"stream":{"type":"boolean","default":false,"description":"If set to True, the model response data will be streamed to the client as it is generated using server-sent events."},"system":{"type":"string","description":"A system prompt is a way of providing context and instructions to Claude, such as specifying a particular goal or role."},"temperature":{"type":"number","minimum":0,"maximum":1,"default":1,"description":"Amount of randomness injected into the response. Defaults to 1.0. Ranges from 0.0 to 1.0. Use temperature closer to 0.0 for analytical / multiple choice, and closer to 1.0 for creative and generative tasks. Note that even with temperature of 0.0, the results will not be fully deterministic."},"tool_choice":{"anyOf":[{"type":"object","properties":{"type":{"type":"string","enum":["auto"]}},"required":["type"]},{"type":"object","properties":{"type":{"type":"string","enum":["any"]}},"required":["type"]},{"type":"object","properties":{"name":{"type":"string"},"type":{"type":"string","enum":["tool"]}},"required":["name","type"]},{"type":"object","properties":{"type":{"type":"string","enum":["none"]}},"required":["type"]}],"description":"Controls which (if any) tool is called by the model. none means the model will not call any tool and instead generates a message. auto means the model can pick between generating a message or calling one or more tools. required means the model must call one or more tools. Specifying a particular tool via {\"type\": \"function\", \"function\": {\"name\": \"my_function\"}} forces the model to call that tool.\n  none is the default when no tools are present. auto is the default if tools are present."},"tools":{"type":"array","items":{"type":"object","properties":{"name":{"type":"string","description":"Name of the tool."},"description":{"type":"string","description":"Description of what this tool does.\n  Tool descriptions should be as detailed as possible. The more information that the model has about what the tool is and how to use it, the better it will perform. You can use natural language descriptions to reinforce important aspects of the tool input JSON schema."},"input_schema":{"type":"object","properties":{"type":{"type":"string","enum":["object"]},"properties":{"nullable":true}},"required":["type"],"additionalProperties":{"nullable":true},"description":"JSON schema for this tool's input.\n  This defines the shape of the input that your tool accepts and that the model will produce."}},"required":["name","input_schema"],"additionalProperties":false},"description":"Definitions of tools that the model may use.\n  If you include tools in your API request, the model may return tool_use content blocks that represent the model's use of those tools. You can then run those tools using the tool input generated by the model and then optionally return results back to the model using tool_result content blocks.\n  Each tool definition includes:\n      name: Name of the tool.\n      description: Optional, but strongly-recommended description of the tool.\n      input_schema: JSON schema for the tool input shape that the model will produce in tool_use output content blocks."},"top_k":{"type":"number","description":"Only sample from the top K options for each subsequent token. Used to remove \"long tail\" low probability responses. Recommended for advanced use cases only. You usually only need to use temperature."},"top_p":{"type":"number","description":"An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered.\n  We generally recommend altering this or temperature but not both."},"thinking":{"type":"object","properties":{"budget_tokens":{"type":"integer","minimum":1024,"description":"Determines how many tokens Claude can use for its internal reasoning process. Larger budgets can enable more thorough analysis for complex problems, improving response quality. Must be ≥1024 and less than max_tokens."},"type":{"type":"string","enum":["enabled"]}},"required":["budget_tokens","type"],"description":"Configuration for enabling Claude's extended thinking. When enabled, responses include thinking content blocks showing Claude's thinking process before the final answer. Requires a minimum budget of 1,024 tokens and counts towards your max_tokens limit."}},"required":["model","messages"],"additionalProperties":false}}},"paths":{"/messages":{"post":{"operationId":"MessagesController_create","parameters":[],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/LlmThreadMessage.v1.CreateMessageDTO"}}}},"responses":{"201":{"description":""}},"tags":["Chat Completions"]}}}}
```

## **Function Calling**

To process text and use function calling, follow the examples below:

### **Example #1: Get Weather Information**

{% code overflow="wrap" %}

```python
import requests

url = "https://api.aimlapi.com/messages"
headers = {
    "Authorization": "Bearer YOUR_AIMLAPI_KEY",
    "Content-Type": "application/json"
}
payload = {
  "model": "claude-3-5-sonnet-20240620",
  "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"
          }
        }
      }
    }
  ],
  "messages": [
    {
      "role": "user",
      "content": "What is the weather like in San Francisco?"
    }
  ],
  "stream": false
}
response = requests.post(url, json=payload, headers=headers)
print(response.json())
```

{% endcode %}

### **Example #2: Simple Text Response**

```python
import requests

url = "https://api.aimlapi.com/messages"
headers = {
    "Authorization": "Bearer YOUR_AIMLAPI_KEY",
    "Content-Type": "application/json"
}
payload = {
  "model": "claude-3-5-sonnet-20240620",
  "max_tokens": 1024,
  "messages": [
    {
      "role": "user",
      "content": "How are you?"
    }
  ],
  "stream": false
}
response = requests.post(url, json=payload, headers=headers)
print(response.json())
```

{% hint style="success" %}
**Pro tip:** you can assign a system role to the Claude models by using "system" parameter outside of messages array.
{% endhint %}

{% code overflow="wrap" %}

```json
{
    model="claude-3-5-sonnet-20240620",
    max_tokens=2048,

    # role prompt:
    system="You are a seasoned data scientist at a Fortune 500 company.", 
    messages=[
        {"role": "user", "content": "Analyze this dataset for anomalies: <dataset>{{DATASET}}</dataset>"}
    ]
}
```

{% endcode %}

## Streaming Mode

To enable streaming of responses, set `stream=True` in your request payload.

```python
import requests

url = "https://api.aimlapi.com/messages"
headers = {
    "Authorization": "Bearer YOUR_AIMLAPI_KEY",
    "Content-Type": "application/json"
}
payload = {
  "model": "claude-3-5-sonnet-20240620",
  "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"
          }
        }
      }
    }
  ],
  "messages": [
    {
      "role": "user",
      "content": "What is the weather like in San Francisco?"
    }
  ]
```

## **Batch Processing**

Due to the complexity of its description, this capability has been placed on [a separate page](https://docs.aimlapi.com/capabilities/batch-processing).

## **Vision**

{% hint style="info" %}
**Note:** API only support [Base64 string](https://docs.aimlapi.com/glossary/concepts#base64) as image input.
{% endhint %}

Possible media types:

* `image/jpeg`
* `image/png`
* `image/gif`
* `image/webp`

{% code overflow="wrap" %}

```python
import httpx
import base64
from openai import OpenAI

client = OpenAI(
    base_url='https://api.aimlapi.com',
    api_key='<YOUR_AIMLAPI_KEY>'    
)  

image_url = "https://upload.wikimedia.org/wikipedia/commons/a/a7/Camponotus_flavomarginatus_ant.jpg"
image_media_type = "image/jpeg"
image_data = base64.standard_b64encode(httpx.get(image_url).content).decode("utf-8")

response = client.chat.completions.create(
    model="claude-3-5-sonnet-latest",
    messages=[
    {
        "role": "user",
        "content": [
            {
                "type": "image",
                "source": {
                    "type": "base64",
                    "media_type": image_media_type,
                    "data": imag1_data,
                },
            },
            {
                "type": "text",
                "text": "Describe this image."
            }
        ],
    }
],
)
print(response)
```

{% endcode %}

***

## Response Format

The responses from the AI/ML API for Anthropic models will typically include the generated text or results from the tool called. Here is an example response for a weather query:

{% code overflow="wrap" %}

```json
{
  "id": "msg-12345",
  "object": "message",
  "created": 1627684940,
  "model": "claude-3-5-sonnet-20240620",
  "choices": [
    {
      "message": {
        "role": "assistant",
        "content": "The weather in San Francisco is currently sunny with a temperature of 68°F."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 10,
    "completion_tokens": 15,
    "total_tokens": 25
  }
}
```

{% endcode %}
