Skip to main content
POST
/
messages
Create message
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: JSON.stringify({
    model: 'anthropic/claude-sonnet-4',
    max_tokens: 512,
    stream: false,
    messages: [{role: 'user', content: 'What time is it in America/New_York right now?'}],
    tools: [{type: 'gateway:datetime', parameters: {timezone: 'America/New_York'}}],
    tool_choice: {type: 'auto'}
  })
};

fetch('https://api.phaseo.app/v1/messages', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));
{
  "id": "<string>",
  "type": "<string>",
  "role": "assistant",
  "model": "<string>",
  "content": [
    {
      "text": "<string>",
      "cache_control": {
        "type": "<string>",
        "ttl": "<string>",
        "scope": "<string>"
      },
      "source": {
        "type": "<string>",
        "media_type": "<string>",
        "data": "<string>",
        "url": "<string>"
      },
      "id": "<string>",
      "name": "<string>",
      "input": {},
      "tool_use_id": "<string>",
      "content": "<string>"
    }
  ],
  "stop_reason": "<string>",
  "stop_sequence": "<string>",
  "usage": {
    "input_tokens": 123,
    "output_tokens": 123
  }
}
/v1/messages accepts Anthropic Messages API payloads and returns Anthropic-formatted responses.

Streaming

Set stream: true to receive server-sent events in Anthropic format (message_start, content_block_*, message_delta, message_stop).

Notes

  • Anthropic tool-use fields are supported.
  • stream: true also works with tool loops. For gateway-managed server tools, AI Stats may materialize the upstream tool-call turn, continue the loop, and re-emit a synthetic stream.
  • The Anthropic-native web search tool shape is also accepted directly in tools, for example type: "web_search_20250305".
  • The X-AIStats-Strictness header controls how unsupported parameters are handled.

Server tools

/v1/messages also supports these gateway-managed server tools:
  • gateway:datetime
  • ai-stats:web_search
  • ai-stats:web_fetch
  • ai-stats:advisor
  • ai-stats:image_generation
AI Stats rewrites these tools to Anthropic-compatible format upstream, executes them server-side, and continues the tool loop. When a compatible Anthropic model/provider pair supports native web search, you can also pass the native tool definition through directly:
curl https://api.phaseo.app/v1/messages \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "anthropic/claude-sonnet-4",
    "max_tokens": 512,
    "messages": [
      { "role": "user", "content": "Find the latest Anthropic web search guidance." }
    ],
    "tools": [
      {
        "type": "web_search_20250305",
        "name": "web_search",
        "max_uses": 3,
        "allowed_domains": ["docs.anthropic.com"]
      }
    ],
    "tool_choice": { "type": "tool", "name": "web_search" }
  }'
Provider routing still filters for web_search_options support before execution.

Datetime example

curl https://api.phaseo.app/v1/messages \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "anthropic/claude-sonnet-4",
    "max_tokens": 512,
    "stream": false,
    "messages": [
      { "role": "user", "content": "What time is it in America/New_York right now?" }
    ],
    "tools": [
      {
        "type": "gateway:datetime",
        "parameters": { "timezone": "America/New_York" }
      }
    ],
    "tool_choice": { "type": "auto" }
  }'
When used, the usage.server_tool_use.* counters report server-tool invocations.

Authorizations

Authorization
string
header
required

Bearer token authentication

Body

application/json
model
string
required
messages
object[]
required
Minimum array length: 1
max_tokens
integer
required
Required range: x >= 1
system
temperature
number
Required range: 0 <= x <= 1
top_p
number
Required range: 0 <= x <= 1
top_k
integer
Required range: x >= 1
tools
object[]

Anthropic-compatible tools plus gateway server tools. The only built-in gateway server tools are gateway:datetime, gateway:web_search, and gateway:web_fetch.

tool_choice

Anthropic tool choice object/string. gateway:datetime, gateway:web_search, and gateway:web_fetch are also accepted and rewritten by the gateway.

stream
boolean
metadata
object
session_id
string

Unique identifier for grouping related requests (for example, a conversation or agent workflow) for observability.

Maximum string length: 256
reasoning
object
stop_sequences
string[]
prompt_cache_retention
string

OpenAI-compatible prompt cache retention policy, such as 24h.

cache_control
object

Provider-neutral prompt cache control hint for automatic caching or cache breakpoints.

provider_options
object

Optional provider-specific options.

usage
boolean
meta
boolean
echo_upstream_request
boolean
debug
object

Gateway debug controls. These flags are never forwarded upstream.

provider
object

Provider routing preferences for gateway selection.

Response

Message response

id
string
type
string
role
enum<string>
Available options:
assistant
model
string
content
object[]
stop_reason
string
stop_sequence
string
usage
object
Last modified on June 11, 2026