> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pipellm.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Messages

> Anthropic-compatible Messages API on PipeLLM

For authentication and model list, see [Overview](/api-reference/anthropic/overview).

## Endpoint

```
POST https://api.pipellm.ai/v1/messages
```

<Note>
  This free route accepts Anthropic Messages requests and routes only to
  Anthropic-compatible platforms. To keep the Anthropic format while calling
  OpenAI or Gemini models, use the
  [Anthropic Format Converter](/converter/anthropic-format).
</Note>

## Install SDKs

<Tabs>
  <Tab title="Python">
    ```bash theme={null}
    pip install anthropic
    ```
  </Tab>

  <Tab title="Node.js">
    ```bash theme={null}
    npm install @anthropic-ai/sdk
    ```
  </Tab>

  <Tab title="Go">
    ```bash theme={null}
    go get github.com/anthropics/anthropic-sdk-go
    ```
  </Tab>
</Tabs>

## Code Examples

<Tabs>
  <Tab title="cURL">
    ```bash theme={null}
    curl https://api.pipellm.ai/v1/messages \
      -H "Content-Type: application/json" \
      -H "x-api-key: $PIPELLM_API_KEY" \
      -H "anthropic-version: 2023-06-01" \
      -d @- << 'EOF'
    {
      "model": "claude-sonnet-4-5-20250929",
      "max_tokens": 1024,
      "messages": [
        {"role": "user", "content": "Why is the sky blue?"}
      ]
    }
    EOF
    ```
  </Tab>

  <Tab title="Python">
    ```python theme={null}
    import os
    import anthropic

    client = anthropic.Anthropic(
      api_key=os.getenv('PIPELLM_API_KEY'),
      base_url='https://api.pipellm.ai'
    )

    message = client.messages.create(
      model='claude-sonnet-4-5-20250929',
      max_tokens=1024,
      messages=[
        {'role': 'user', 'content': 'Why is the sky blue?'}
      ]
    )

    print(message.content[0].text)
    ```
  </Tab>

  <Tab title="Node.js">
    ```javascript theme={null}
    import Anthropic from '@anthropic-ai/sdk';

    const client = new Anthropic({
      apiKey: process.env.PIPELLM_API_KEY,
      baseURL: 'https://api.pipellm.ai'
    });

    const message = await client.messages.create({
      model: 'claude-sonnet-4-5-20250929',
      max_tokens: 1024,
      messages: [
        { role: 'user', content: 'Why is the sky blue?' }
      ]
    });

    console.log(message.content[0].text);
    ```
  </Tab>

  <Tab title="Go">
    ```go theme={null}
    package main

    import (
      "context"
      "os"
      "github.com/anthropics/anthropic-sdk-go"
      "github.com/anthropics/anthropic-sdk-go/option"
    )

    func main() {
      client := anthropic.NewClient(
        option.WithAPIKey(os.Getenv("PIPELLM_API_KEY")),
        option.WithBaseURL("https://api.pipellm.ai"),
      )

      message, _ := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
        Model:     anthropic.F("claude-sonnet-4-5-20250929"),
        MaxTokens: anthropic.Int(1024),
        Messages: anthropic.F([]anthropic.MessageParam{
          anthropic.NewUserMessage(anthropic.NewTextBlock("Why is the sky blue?")),
        }),
      })
    }
    ```
  </Tab>
</Tabs>

## Request Parameters

| Parameter     | Type    | Required | Description                                   |
| ------------- | ------- | -------- | --------------------------------------------- |
| `model`       | string  | Yes      | Model ID (e.g., `claude-sonnet-4-5-20250929`) |
| `messages`    | array   | Yes      | Array of message objects                      |
| `max_tokens`  | integer | Yes      | Maximum tokens to generate                    |
| `temperature` | number  | No       | Sampling temperature (0-1)                    |
| `stream`      | boolean | No       | Enable streaming response                     |

## Response Format

```json theme={null}
{
  "id": "msg_xxx",
  "type": "message",
  "role": "assistant",
  "content": [
    {"type": "text", "text": "The sky appears blue because..."}
  ],
  "model": "claude-sonnet-4-5-20250929",
  "stop_reason": "end_turn",
  "usage": {
    "input_tokens": 10,
    "output_tokens": 50
  }
}
```

## Related Docs

<Columns cols={3}>
  <Card title="Routing & Protocols" icon="route" href="/guides/routing-protocols">
    Native-route constraints and converter routes
  </Card>

  <Card title="Anthropic Overview" icon="message" href="/api-reference/anthropic/overview">
    Headers, models, and route family overview
  </Card>

  <Card title="Anthropic Format Converter" icon="shuffle" href="/converter/anthropic-format">
    Keep Anthropic format while calling other providers
  </Card>
</Columns>
