Skip to main content
POST
/
api
/
v1
/
messages
curl --request POST \
  --url https://api.crun.ai/api/v1/messages \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "model": "claude-sonnet-4-6",
  "max_tokens": 512,
  "messages": [
    {
      "role": "user",
      "content": "Write a concise project update for a payments API migration."
    }
  ]
}
'
{
  "id": "msg_abc123",
  "type": "message",
  "role": "assistant",
  "model": "claude-sonnet-4-6",
  "content": [
    {
      "type": "text",
      "text": "The payments API migration is on track. Authentication updates are complete, integration testing is in progress, and rollback criteria will be finalized before release."
    }
  ],
  "stop_reason": "end_turn",
  "stop_sequence": null,
  "usage": {
    "input_tokens": 18,
    "output_tokens": 34
  }
}

API Endpoint

POST https://api.crun.ai/api/v1/messages
This endpoint follows the Anthropic Messages API request and response shape. It is designed for Claude-compatible clients while using your CRUN API key and CRUN public model IDs.

Authentication

You can authenticate with either:
  • Authorization: Bearer YOUR_API_KEY
  • X-API-KEY: YOUR_API_KEY
Optional Anthropic request headers such as anthropic-version and anthropic-beta are accepted and forwarded upstream when provided.

Basic Message

curl -X POST "https://api.crun.ai/api/v1/messages" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -H "anthropic-version: 2023-06-01" \
  -d '{
    "model": "claude-sonnet-4-6",
    "max_tokens": 512,
    "messages": [
      {
        "role": "user",
        "content": "Write a concise project update for a payments API migration."
      }
    ]
  }'

System Prompt

Anthropic Messages uses a top-level system field instead of a system role in the messages array.
request body
{
  "model": "claude-sonnet-4-6",
  "max_tokens": 800,
  "system": "You are a senior API documentation editor. Be concise and precise.",
  "messages": [
    {
      "role": "user",
      "content": "Rewrite this changelog entry for developers: fixed auth bug."
    }
  ]
}

Conversation History

CRUN does not store conversation state for /messages. To continue a conversation, include the prior user and assistant turns in the next request.
request body
{
  "model": "claude-sonnet-4-6",
  "max_tokens": 800,
  "messages": [
    {
      "role": "user",
      "content": "Give me three names for an internal developer newsletter."
    },
    {
      "role": "assistant",
      "content": "Here are three options: Build Notes, Ship Log, and Dev Dispatch."
    },
    {
      "role": "user",
      "content": "Make them sound more enterprise-ready."
    }
  ]
}

Vision Input

When the selected model supports vision, pass a content array with text and image blocks. Image sources can use a URL/file source.
{
  "model": "claude-sonnet-4-6",
  "max_tokens": 800,
  "messages": [
    {
      "role": "user",
      "content": [
        {
          "type": "text",
          "text": "Summarize the product shown in this image."
        },
        {
          "type": "image",
          "source": {
            "type": "url",
            "url": "https://example.com/product-photo.png"
          }
        }
      ]
    }
  ]
}

Tool Use

Pass tools to let the model request structured function calls. Your application executes the tool and sends the result back in a follow-up message.
request body
{
  "model": "claude-sonnet-4-6",
  "max_tokens": 1024,
  "messages": [
    {
      "role": "user",
      "content": "What is the weather in Paris?"
    }
  ],
  "tools": [
    {
      "name": "get_weather",
      "description": "Get current weather for a city.",
      "input_schema": {
        "type": "object",
        "properties": {
          "city": {
            "type": "string"
          }
        },
        "required": ["city"]
      }
    }
  ],
  "tool_choice": {
    "type": "auto"
  }
}

Thinking

When supported by the selected model and upstream provider, use thinking to request extended reasoning behavior.
request body
{
  "model": "claude-sonnet-4-6",
  "max_tokens": 2048,
  "thinking": {
    "type": "enabled",
    "budget_tokens": 1024
  },
  "messages": [
    {
      "role": "user",
      "content": "Compare two API migration plans and recommend the lower-risk option."
    }
  ]
}

Streaming

Set stream=true to receive Anthropic-style Server-Sent Events.
curl -N "https://api.crun.ai/api/v1/messages" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -H "anthropic-version: 2023-06-01" \
  -d '{
    "model": "claude-sonnet-4-6",
    "max_tokens": 512,
    "stream": true,
    "messages": [
      {
        "role": "user",
        "content": "Write a three-bullet checklist for API release readiness."
      }
    ]
  }'

Response Examples

{
  "id": "msg_abc123",
  "type": "message",
  "role": "assistant",
  "model": "claude-sonnet-4-6",
  "content": [
    {
      "type": "text",
      "text": "The payments API migration is on track. Authentication updates are complete, integration testing is in progress, and rollback criteria will be finalized before release."
    }
  ],
  "stop_reason": "end_turn",
  "stop_sequence": null,
  "usage": {
    "input_tokens": 18,
    "output_tokens": 34
  }
}

Notes

  • max_tokens is capped by the selected model’s output token limit when configured in CRUN.
  • messages only supports user and assistant roles. Use the top-level system field for system instructions.
  • Additional Anthropic-compatible fields are accepted and passed through when supported by the upstream model.
  • Tool use, thinking, image blocks, URL sources, and beta features depend on the selected model and upstream provider.
  • Unknown model IDs return an OpenAI-style error body with code: "model_not_found".

LLM Quickstart

Learn the base URL, authentication method, and SDK integration patterns.

OpenAI Responses API

Build OpenAI-compatible workflows with flexible input, structured outputs, and streaming.

Pricing

Jump to the pricing page to compare billing across different models.

Authorizations

Authorization
string
header
required

Use your CRUN API key as a Bearer token for Anthropic-compatible SDKs.

Headers

anthropic-version
string

Optional Anthropic API version header forwarded upstream.

Example:

"2023-06-01"

anthropic-beta
string

Optional Anthropic beta feature header forwarded upstream.

Body

application/json

Anthropic-compatible Messages request. Additional compatible fields are accepted and passed through when supported by the upstream model.

model
string
required

Public model ID returned by GET /api/v1/models.

Minimum string length: 1
Example:

"claude-sonnet-4-6"

messages
object[]
required

Conversation messages. Include previous user and assistant turns yourself to continue a multi-turn conversation.

Minimum array length: 1
max_tokens
integer

Maximum output tokens. Capped by the selected model.

Required range: x >= 1
Example:

1024

system

System prompt. Anthropic Messages uses a top-level system field.

Example:

"You are a concise assistant."

stream
boolean
default:false

Whether to return a Server-Sent Events stream.

Example:

false

stop_sequences
string[]

List of stop sequences.

Example:
["END"]
temperature
number

Sampling temperature.

Required range: 0 <= x <= 1
Example:

0.7

top_p
number

Nucleus sampling value.

Required range: 0 <= x <= 1
Example:

1

top_k
integer

Top-k sampling value.

Required range: x >= 0
Example:

40

metadata
object

Developer-defined metadata.

tools
object[]

Anthropic tool definitions. Your application executes tool calls and returns tool results in a follow-up request.

tool_choice

Tool selection strategy.

Example:

"auto"

thinking
object

Extended thinking configuration when supported by the upstream model.

Example:
{ "type": "enabled", "budget_tokens": 1024 }

Response

Successful response. Returns JSON when stream=false, or SSE when stream=true.

Anthropic Messages response.

id
string
Example:

"msg_abc123"

type
string
Example:

"message"

role
string
Example:

"assistant"

model
string
Example:

"claude-sonnet-4-6"

content
object[]
stop_reason
string | null
Example:

"end_turn"

stop_sequence
string | null
usage
object

Anthropic usage information.