Skip to content

Anthropic Messages

POST https://api.i14.ai/v1/messages

Use this route when your client speaks the Anthropic Messages format and your model supports it. Models that only support Chat Completions and Completions cannot be used on this route. The Models endpoint tells you what your key can access, not which protocols or features each deployment supports.

Pass your i14 key to the Anthropic SDK and set the base URL to https://api.i14.ai, without /v1. For raw HTTP, send either Authorization: Bearer YOUR_API_KEY or x-api-key: YOUR_API_KEY. You do not need a separate Anthropic key.

Field Type Meaning
model string, required A compatible model ID your key is allowed to use.
messages array, required Conversation history of user and assistant messages, in order. The content can be a string or supported content blocks.
max_tokens integer, required Maximum number of tokens to generate.
system string or array System instructions, separate from the message list.
temperature, top_p, top_k number Sampling controls, where supported.
stop_sequences array Sequences that stop generation.
tools, tool_choice array, object Client tools and selection controls on compatible models. Your client runs the tool.
thinking object On compatible models {"type":"enabled"} enables thinking and {"type":"disabled"} disables it. The gateway does not promise a separate thinking budget.
stream boolean Receive Anthropic-style server-sent events instead of a single message.

Set I14_MODEL to an ID that supports Messages. Install the Anthropic SDK with pip install anthropic.

import os
from anthropic import Anthropic
client = Anthropic(base_url="https://api.i14.ai", api_key=os.environ["I14_API_KEY"])
message = client.messages.create(
model=os.environ["I14_MODEL"],
max_tokens=256,
messages=[{"role": "user", "content": "What is a token?"}],
)
for block in message.content:
if block.type == "text":
print(block.text)

The response is an assistant message with an ordered content array, stop_reason, and usage when available. Example (selected fields):

{
"id": "msg_example",
"type": "message",
"role": "assistant",
"model": "your-model-id",
"content": [{"type": "text", "text": "A token is a unit of text a model processes."}],
"stop_reason": "end_turn",
"usage": {"input_tokens": 12, "output_tokens": 11}
}

When streaming, use the Anthropic SDK’s Messages stream or dispatch events by type. Accumulate only text deltas for visible text, and handle non-text content blocks separately. An interrupted stream is not a completed message.

POST https://api.i14.ai/v1/messages/count_tokens

Send the model and messages you intend to use. You can also include the system instructions and tool definitions that will be part of that request. This endpoint does not generate an answer. On success, it returns an input_tokens count.

{"input_tokens": 12}

The Messages routes use the Anthropic error envelope: an outer type: "error" and an error object with a type and message. Check the HTTP status before retrying.