# Create a message

> POST /v1/messages — send a conversation and get the model's next message.

Source: https://docs.strokes.ink/api/messages

```http
POST https://api.strokes.ink/v1/messages
```

## Request

### Headers

| Header | |
| --- | --- |
| `x-api-key` | **Required.** Your API key. `Authorization: Bearer <key>` also works |
| `content-type` | **Required.** `application/json` |

### Body

| Field | Type | |
| --- | --- | --- |
| `model` | string | **Required.** `swim-1.0`. See [Models](/api/models) |
| `max_tokens` | integer | The most tokens the reply may have, reasoning included. From `1` to the model's maximum, 32,000, which is also the default. The Anthropic SDKs require it: send `32000` |
| `messages` | array | **Required.** The conversation so far, oldest first. At least one message |
| `messages[].role` | string | **Required.** `user` or `assistant` |
| `messages[].content` | string or array | **Required.** The message's text, or a list of [content blocks](#content-blocks) |
| `system` | string or array | A system prompt: a string, or a list of text blocks |
| `stream` | boolean | `true` to receive the reply as [server-sent events](/api/streaming-events). Default `false` |
| `stop_sequences` | array | Up to 4 non-empty strings. The reply stops where the model writes one |
| `temperature` | number | From `0` to `1` |
| `top_p` | number | From `0` to `1` |
| `tools` | array | [Tools](#tools) the model may call |
| `tool_choice` | object | How the model uses the tools: [tool choice](#tool-choice) |
| `output_config.effort` | string | How much the model reasons: `low` (the default), `medium`, `high` or `max`. See [reasoning level](#reasoning-level) |
| `thinking` | object | Whether the reasoning is returned: `{ "type": "adaptive" }` or `{ "type": "enabled" }` returns it as `thinking` blocks, `"display": "omitted"` hides it, `{ "type": "disabled" }` reasons at `low`. `budget_tokens` is ignored. See [reasoning level](#reasoning-level) |
| `web_search` | boolean | Whether the model may search the web and read pages. Default `true` for `swim-1.0`. See [Web search](/guides/web-search) |
| `stroke_id` | string | The [stroke](/guides/strokes) the request belongs to: 1 to 200 letters, digits or `.` `_` `:` `-`. The `stroke-id` header works too |
| `mode` | string | The kind of writing: `business`, `academic` or `creative`. Left out, the API picks one for the request. See [Modes](/guides/modes) |

Other fields of Anthropic's Messages API, such as `metadata`, are accepted and ignored. These answer `400 invalid_request_error`: `top_k`, `container` and `mcp_servers`.

### Content blocks

In a `user` message:

| Block | |
| --- | --- |
| `{ "type": "text", "text": "…" }` | Text |
| `{ "type": "image", "source": { "type": "base64", "media_type": "image/png", "data": "…" } }` | An image, inline |
| `{ "type": "image", "source": { "type": "url", "url": "https://…" } }` | An image, by URL |
| `{ "type": "tool_result", "tool_use_id": "toolu_…", "content": "…", "is_error": false }` | Your answer to a `tool_use`. `content` is a string or a list of text blocks; `is_error` is optional |

In an `assistant` message: `text`, `tool_use`, and the web search blocks `server_tool_use`, `web_search_tool_result` and `web_fetch_tool_result` — send the model's earlier replies back as they came. `thinking` and `redacted_thinking` blocks are accepted and dropped: the model never sees its earlier reasoning.

`document` blocks (PDFs and other files) aren't supported and answer `400`.

### Tools

A custom tool, which your code runs:

```json
{
  "name": "get_word_count",
  "description": "Counts the words in a draft.",
  "input_schema": {
    "type": "object",
    "properties": { "draft_id": { "type": "string" } },
    "required": ["draft_id"]
  }
}
```

`type` may be left out or set to `custom`. `name` and `input_schema` are required.

Web search needs no tool: the model has it on every request unless you send `"web_search": false`. You can also declare `web_search_20250305` (`name: "web_search"`) or `web_fetch_20250910` (`name: "web_fetch"`) to override `max_uses` (1–10), `allowed_domains`, `blocked_domains` or `max_content_tokens` — see [Web search](/guides/web-search).

### Tool choice

| `tool_choice` | |
| --- | --- |
| `{ "type": "auto" }` | The model decides. The default |
| `{ "type": "any" }` | The model must call a tool |
| `{ "type": "tool", "name": "…" }` | The model must call this tool |
| `{ "type": "none" }` | The model must not call a tool |

Add `"disable_parallel_tool_use": true` to get at most one call per reply. Every type but `none` needs `tools`.

### Reasoning level

`output_config.effort` sets how much the model reasons before it answers:

```json
{ "output_config": { "effort": "high" } }
```

| `effort` | |
| --- | --- |
| `low` | The default, when `output_config` is left out or `thinking` is `disabled`. Little or no reasoning |
| `medium` | Runs as `high` |
| `high` | Some reasoning |
| `max` | Reasons in full, often thousands of tokens |

Reasoning tokens count toward `output_tokens` and `max_tokens` — if you set `max_tokens`, leave room for them. If the model spends all of `max_tokens` reasoning and writes nothing, the API asks it again one level lower; every attempt is billed.

The reasoning is returned only with `thinking` of type `adaptive` or `enabled`: a `thinking` block, `{ "type": "thinking", "thinking": "…", "signature": "" }`, before the text. See [Messages](/guides/messages#see-the-reasoning).

### Example

<Tabs items={["curl","TypeScript","Python"]}>
<Tab value="curl">
```bash
curl https://api.strokes.ink/v1/messages \
  -H "x-api-key: $STROKES_API_KEY" \
  -H "content-type: application/json" \
  -d '{
    "model": "swim-1.0",
    "system": "You are a concise copy editor.",
    "messages": [
      {
        "role": "user",
        "content": "Tighten: We are very excited to be able to announce our new product."
      }
    ]
  }'
```
</Tab>

<Tab value="TypeScript">
```ts
const message = await client.messages.create({
  model: "swim-1.0",
  max_tokens: 32000,
  system: "You are a concise copy editor.",
  messages: [
    {
      role: "user",
      content: "Tighten: We are very excited to be able to announce our new product.",
    },
  ],
});
```
</Tab>

<Tab value="Python">
```python
message = client.messages.create(
    model="swim-1.0",
    max_tokens=32000,
    system="You are a concise copy editor.",
    messages=[
        {
            "role": "user",
            "content": "Tighten: We are very excited to be able to announce our new product.",
        }
    ],
)
```
</Tab>
</Tabs>

## Response

A `message` object:

```json
{
  "id": "msg_4bJ8wqT2nV9sKx1LmP0aR7cZ",
  "type": "message",
  "role": "assistant",
  "model": "swim-1.0",
  "content": [
    {
      "type": "text",
      "text": "We're excited to announce our new product."
    }
  ],
  "stop_reason": "end_turn",
  "stop_sequence": null,
  "usage": {
    "input_tokens": 31,
    "cache_creation_input_tokens": 0,
    "cache_read_input_tokens": 0,
    "output_tokens": 112
  }
}
```

| Field | Type | |
| --- | --- | --- |
| `id` | string | The message's unique ID, `msg_…` |
| `type` | string | Always `message` |
| `role` | string | Always `assistant` |
| `model` | string | The model that wrote the reply |
| `content` | array | The reply's blocks, in order: `thinking` (when you asked for the reasoning), `text`, `tool_use` (a call for your code to run, with an `id` like `toolu_…`), and when the model searched the web `server_tool_use`, `web_search_tool_result` and `web_fetch_tool_result` |
| `stop_reason` | string | Why the reply ended — see below |
| `stop_sequence` | null | Always `null` |
| `usage.input_tokens` | integer | Tokens read that weren't in the [prompt cache](/guides/messages#prompt-caching): the system prompt, messages and tools — every round, when the API searched the web in between |
| `usage.cache_read_input_tokens` | integer | Tokens read from the prompt cache. All input is `input_tokens` plus this |
| `usage.cache_creation_input_tokens` | integer | Always `0`: writing to the cache costs nothing |
| `usage.output_tokens` | integer | Tokens written, reasoning included |
| `usage.server_tool_use` | object | Present when the model searched the web: `web_search_requests` and `web_fetch_requests`, the searches and page reads billed |

| `stop_reason` | |
| --- | --- |
| `end_turn` | The model finished, or wrote one of your `stop_sequences` |
| `max_tokens` | The reply hit `max_tokens` and was cut off |
| `tool_use` | The model called one of your tools. Run it and send a `tool_result` — see [Tool use](/guides/tool-use) |
| `pause_turn` | The model was still searching the web after 12 rounds. Send the reply back to let it go on — see [Web search](/guides/web-search#pause_turn) |
| `refusal` | The model declined to answer |

## Errors

| Status | Type | When |
| --- | --- | --- |
| `400` | `invalid_request_error` | The body isn't JSON, a field is missing, of the wrong type or not supported, or `max_tokens` is above the model's maximum |
| `401` | `authentication_error` | The key is missing, wrong, disabled or deleted |
| `402` | `billing_error` | The organization is out of credits, or the key reached its monthly spend limit |
| `404` | `not_found_error` | `model` isn't a model the API serves |
| `529` | `overloaded_error` | The model is busy. Retry with backoff |
| `500` | `api_error` | Something went wrong on our side. Retry |

See [Errors](/api/errors) for the body and the messages.
