synthetic
    API
    • Overview
    • Getting Started
    • Models
    OpenAI Reference
    • /models
    • /chat/completions
    • /completions
    • /embeddings
    Anthropic Reference
    • /messages
    • /messages/count_tokens
    Synthetic Reference
    • /quotas
    Guides
    • Claude Code
    • Octofriend by Synthetic
    • Xcode Intelligence
    • Back to app

    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

    ParameterTypeRequiredDescription
    modelstringYesModel name (must be prefixed with hf:). See supported Models.
    max_tokensnumberYesMaximum number of tokens to generate
    messagesarrayYesArray of message objects
    streambooleanNoWhether to stream the response
    systemstring/arrayNoSystem message(s) - can be string or array of system message objects
    stop_sequencesarrayNoStop sequences
    temperaturenumberNoSampling temperature
    tool_choiceobjectNoControl tool calling: auto, any, none, or specific tool
    toolsarrayNoList of tools the model may call
    top_knumberNoLimit sampling to top K tokens
    top_pnumberNoNucleus sampling parameter

    Message Object

    ParameterTypeRequiredDescription
    rolestringYesRole: user or assistant
    contentstring/arrayYesMessage content (string or array of one or more of the following content objects)

    Text Content Object

    ParameterTypeRequiredDescription
    typestringYesMust be "text"
    textstringYesThe text content

    Image Content Object

    ParameterTypeRequiredDescription
    typestringYesMust be "image"
    sourceobjectYesImage source object

    Image Source (Base64)

    ParameterTypeRequiredDescription
    typestringYesMust be "base64"
    media_typestringYesMIME type (e.g., image/jpeg, image/png)
    datastringYesBase64 encoded image data

    Image Source (URL)

    ParameterTypeRequiredDescription
    typestringYesMust be "url"
    urlstringYesURL to the image

    Tool Use Content Object

    ParameterTypeRequiredDescription
    typestringYesMust be "tool_use"
    idstringYesUnique identifier for this tool use
    namestringYesName of the tool to use
    inputanyYesInput parameters for the tool

    Tool Result Content Object

    ParameterTypeRequiredDescription
    typestringYesMust be "tool_result"
    tool_use_idstringYesID of the tool use this is a result for
    contentstringYesThe result content
    is_errorbooleanNoWhether this represents an error

    Thinking Content Object

    ParameterTypeRequiredDescription
    typestringYesMust be "thinking"
    thinkingstringYesThe thinking/reasoning content

    Redacted Thinking Content Object

    ParameterTypeRequiredDescription
    typestringYesMust be "redacted_thinking"

    Tool Object

    ParameterTypeRequiredDescription
    namestringYesName of the tool
    descriptionstringNoDescription of what the tool does
    input_schemaobjectYesJSON schema for the tool's input

    Tool Input Schema

    ParameterTypeRequiredDescription
    typestringYesMust be "object"
    propertiesobjectNoObject properties definition
    requiredarrayNoArray 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

    ParameterTypeRequiredDescription
    typestringYesType: text
    textstringYesMessage 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="")