Messages API
POST https://api.synthetic.new/anthropic/v1/messages
Send and receive messages.
Tip
To learn how to set up Claude Code with Synthetic, see our Claude Code guide!
Request Body
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Model name (must be prefixed with hf:). See supported Models. |
max_tokens | number | Yes | Maximum number of tokens to generate |
messages | array | Yes | Array of message objects |
stream | boolean | No | Whether to stream the response |
system | string/array | No | System message(s) - can be string or array of system message objects |
stop_sequences | array | No | Stop sequences |
temperature | number | No | Sampling temperature |
tool_choice | object | No | Control tool calling: auto, any, none, or specific tool |
tools | array | No | List of tools the model may call |
top_k | number | No | Limit sampling to top K tokens |
top_p | number | No | Nucleus sampling parameter |
Message Object
| Parameter | Type | Required | Description |
|---|---|---|---|
role | string | Yes | Role: user or assistant |
content | string/array | Yes | Message content (string or array of one or more of the following content objects) |
Text Content Object
| Parameter | Type | Required | Description |
|---|---|---|---|
type | string | Yes | Must be "text" |
text | string | Yes | The text content |
Image Content Object
| Parameter | Type | Required | Description |
|---|---|---|---|
type | string | Yes | Must be "image" |
source | object | Yes | Image source object |
Image Source (Base64)
| Parameter | Type | Required | Description |
|---|---|---|---|
type | string | Yes | Must be "base64" |
media_type | string | Yes | MIME type (e.g., image/jpeg, image/png) |
data | string | Yes | Base64 encoded image data |
Image Source (URL)
| Parameter | Type | Required | Description |
|---|---|---|---|
type | string | Yes | Must be "url" |
url | string | Yes | URL to the image |
Tool Use Content Object
| Parameter | Type | Required | Description |
|---|---|---|---|
type | string | Yes | Must be "tool_use" |
id | string | Yes | Unique identifier for this tool use |
name | string | Yes | Name of the tool to use |
input | any | Yes | Input parameters for the tool |
Tool Result Content Object
| Parameter | Type | Required | Description |
|---|---|---|---|
type | string | Yes | Must be "tool_result" |
tool_use_id | string | Yes | ID of the tool use this is a result for |
content | string | Yes | The result content |
is_error | boolean | No | Whether this represents an error |
Thinking Content Object
| Parameter | Type | Required | Description |
|---|---|---|---|
type | string | Yes | Must be "thinking" |
thinking | string | Yes | The thinking/reasoning content |
Redacted Thinking Content Object
| Parameter | Type | Required | Description |
|---|---|---|---|
type | string | Yes | Must be "redacted_thinking" |
Tool Object
| Parameter | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Name of the tool |
description | string | No | Description of what the tool does |
input_schema | object | Yes | JSON schema for the tool's input |
Tool Input Schema
| Parameter | Type | Required | Description |
|---|---|---|---|
type | string | Yes | Must be "object" |
properties | object | No | Object properties definition |
required | array | No | Array of required property names |
Tool Choice Object
Can be one of:
{"type": "auto"}- Let the model decide whether to use tools{"type": "any"}- Force the model to use at least one tool{"type": "none"}- Prevent the model from using tools{"type": "tool", "name": "tool_name"}- Force use of a specific tool
System Message Object
| Parameter | Type | Required | Description |
|---|---|---|---|
type | string | Yes | Type: text |
text | string | Yes | Message content |
Example Usage
- Python
- TypeScript
- curl
import anthropic
client = anthropic.Anthropic(
api_key="SYNTHETIC_API_KEY",
base_url="https://api.synthetic.new/anthropic/v1"
)
response = client.messages.create(
model="hf:deepseek-ai/DeepSeek-V3-0324",
max_tokens=100,
messages=[
{"role": "user", "content": "What is the capital of France?"}
]
)
print(response.content[0].text)Example Response
- json
{
"id": "msg_abc123",
"type": "message",
"role": "assistant",
"content": [
{
"type": "text",
"text": "The capital of France is Paris."
}
],
"model": "hf:deepseek-ai/DeepSeek-V3-0324",
"stop_reason": "end_turn",
"stop_sequence": null,
"usage": {
"input_tokens": 12,
"output_tokens": 8
}
}
Streaming
When stream: true is set, the response will be a series of Server-Sent Events:
- Python
- TypeScript
- curl
stream = client.messages.create(
model="hf:deepseek-ai/DeepSeek-V3-0324",
max_tokens=100,
system="You are a helpful assistant.",
messages=[{"role": "user", "content": "Hello!"}],
stream=True
)
for event in stream:
if event.type == "content_block_delta":
print(event.delta.text, end="")