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
Authorizations
AuthorizationstringRequired

Bearer key

Body
modelstring · enumRequiredPossible values:
max_tokensnumber · min: 1Optional

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.

Default: 1024
stop_sequencesstring[]Optional

Custom text sequences that will cause the model to stop generating.

streambooleanOptional

If set to True, the model response data will be streamed to the client as it is generated using server-sent events.

Default: false
systemstringOptional

A system prompt is a way of providing context and instructions to Claude, such as specifying a particular goal or role.

temperaturenumber · max: 1Optional

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.

Default: 1
tool_choiceany ofOptional

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. none is the default when no tools are present. auto is the default if tools are present.

or
or
or
top_knumberOptional

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_pnumberOptional

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. We generally recommend altering this or temperature but not both.

Responses
post
/messages
201Success

No content

Function Calling

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

Example #1: Get Weather Information

Example #2: Simple Text Response

Streaming Mode

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

Batch Processing

Due to the complexity of its description, this capability has been placed on a separate page.

Vision

Note: API only support Base64 string as image input.

Possible media types:

  • image/jpeg

  • image/png

  • image/gif

  • image/webp


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:

Last updated

Was this helpful?