# Anthropic Messages API

`POST /v1/messages`

Request in the Anthropic Claude Messages API format.
The `anthropic-version` header is required.

## Authorizations

Bearer authentication — send `Authorization: Bearer <token>`.

## Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `anthropic-version` | header | string | yes | Anthropic API version |
| `x-api-key` | header | string | no | Anthropic API key (optional — a Bearer token also works) |

## Request Body (application/json)

```json
{
  "type": "object",
  "required": [
    "model",
    "messages",
    "max_tokens"
  ],
  "properties": {
    "model": {
      "type": "string",
      "example": "claude-3-opus-20240229"
    },
    "messages": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "role",
          "content"
        ],
        "properties": {
          "role": {
            "type": "string",
            "enum": [
              "user",
              "assistant"
            ]
          },
          "content": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "enum": [
                        "text",
                        "image",
                        "tool_use",
                        "tool_result"
                      ]
                    },
                    "text": {
                      "type": "string"
                    },
                    "source": {
                      "type": "object",
                      "properties": {
                        "type": {
                          "type": "string",
                          "enum": [
                            "base64",
                            "url"
                          ]
                        },
                        "media_type": {
                          "type": "string"
                        },
                        "data": {
                          "type": "string"
                        },
                        "url": {
                          "type": "string"
                        }
                      }
                    },
                    "id": {
                      "type": "string"
                    },
                    "name": {
                      "type": "string"
                    },
                    "input": {
                      "type": "object",
                      "properties": {}
                    },
                    "tool_use_id": {
                      "type": "string"
                    },
                    "content": {
                      "type": "string"
                    }
                  }
                }
              }
            ]
          }
        }
      }
    },
    "system": {
      "oneOf": [
        {
          "type": "string"
        },
        {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {}
          }
        }
      ]
    },
    "max_tokens": {
      "type": "integer",
      "minimum": 1
    },
    "temperature": {
      "type": "number",
      "minimum": 0,
      "maximum": 1
    },
    "top_p": {
      "type": "number"
    },
    "top_k": {
      "type": "integer"
    },
    "stream": {
      "type": "boolean"
    },
    "stop_sequences": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "tools": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "input_schema": {
            "type": "object",
            "properties": {}
          }
        }
      }
    },
    "tool_choice": {
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "enum": [
                "auto",
                "any",
                "tool"
              ]
            },
            "name": {
              "type": "string"
            }
          }
        }
      ]
    },
    "thinking": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "enabled",
            "disabled"
          ]
        },
        "budget_tokens": {
          "type": "integer"
        }
      }
    },
    "metadata": {
      "type": "object",
      "properties": {
        "user_id": {
          "type": "string"
        }
      }
    }
  }
}
```

## Responses

### 200 — Response created

```json
{
  "type": "object",
  "properties": {
    "id": {
      "type": "string"
    },
    "type": {
      "type": "string",
      "example": "message"
    },
    "role": {
      "type": "string",
      "example": "assistant"
    },
    "content": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "type": {
            "type": "string"
          },
          "text": {
            "type": "string"
          }
        }
      }
    },
    "model": {
      "type": "string"
    },
    "stop_reason": {
      "type": "string",
      "enum": [
        "end_turn",
        "max_tokens",
        "stop_sequence",
        "tool_use"
      ]
    },
    "usage": {
      "type": "object",
      "properties": {
        "input_tokens": {
          "type": "integer"
        },
        "output_tokens": {
          "type": "integer"
        },
        "cache_creation_input_tokens": {
          "type": "integer"
        },
        "cache_read_input_tokens": {
          "type": "integer"
        }
      }
    }
  }
}
```
