# Messages

> The Anthropic Messages endpoint POST /v1/messages for Claude models, also used by clients such as Claude Code. The Base URL has no /v1.

`POST https://api.goodapi.tech/v1/messages` is the Anthropic Messages endpoint for Claude models. Requests and responses match the official Anthropic API.

> With an Anthropic SDK or client, set the Base URL to `https://api.goodapi.tech`, **without** `/v1`. The SDK appends `/v1/messages` itself; an extra `/v1` turns it into `/v1/v1/messages`.

## Request

Either authentication style works:

| Style | Headers |
|---|---|
| Bearer | `Authorization: Bearer sk-...` |
| Anthropic style | `x-api-key: sk-...` plus `anthropic-version: 2023-06-01` |

Send the body in Anthropic Messages format:

| Field | Description |
|---|---|
| `model` | Claude model name; see [Models and pricing](/en/docs/models) |
| `max_tokens` | Required; the maximum number of tokens to generate |
| `messages` | Array of messages; `role` is `user` or `assistant` |
| `system` | Optional system prompt |
| `stream` | Optional; `true` for streaming |

## Example

```bash
curl https://api.goodapi.tech/v1/messages \
  -H "x-api-key: $GOODAPI_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet-5-5",
    "max_tokens": 1024,
    "messages": [{"role": "user", "content": "Introduce yourself in one sentence."}]
  }'
```

Response (excerpt):

```json
{
  "id": "msg_...",
  "type": "message",
  "role": "assistant",
  "model": "claude-sonnet-5-5",
  "content": [{"type": "text", "text": "..."}],
  "stop_reason": "end_turn",
  "usage": {"input_tokens": 18, "output_tokens": 24, "cache_read_input_tokens": 0}
}
```

The reply text is in `content[].text`.

## Streaming

With `"stream": true` the response becomes SSE. Events arrive in this order: `message_start`, `content_block_start`, a number of `content_block_delta` events (text delta in `delta.text`), `content_block_stop`, `message_delta` (with `stop_reason` and the final usage), and `message_stop`.

## Using an SDK

```python
import os
import anthropic

client = anthropic.Anthropic(
    api_key=os.environ["GOODAPI_API_KEY"],
    base_url="https://api.goodapi.tech",
)

with client.messages.stream(
    model="claude-sonnet-5-5",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hello"}],
) as stream:
    for text in stream.text_stream:
        print(text, end="", flush=True)
```

```javascript
import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic({
  apiKey: process.env.GOODAPI_API_KEY,
  baseURL: "https://api.goodapi.tech",
});

const message = await client.messages.create({
  model: "claude-sonnet-5-5",
  max_tokens: 1024,
  messages: [{ role: "user", content: "Hello" }],
});
console.log(message.content[0].text);
```

Claude models can also use [Chat Completions](/en/docs/chat-completions).
