Anthropic Messages API
An Anthropic-compatible /v1/messages endpoint so the Anthropic SDKs and Claude Code work out of the box.
Pendra speaks Anthropic's Messages format, so the Anthropic SDKs and
Claude Code work with Pendra
models. Set the base URL to https://api.pendra.ai and use a
Pendra API key.
Authentication
Send your key in the x-api-key header, as Anthropic clients
do. Authorization: Bearer works too.
model
string
Required
qwen3.6:27b. Leave off the quant to use whichever one you installed. See Naming a model.
max_tokens
integer
Required
messages
array
Required
{ role, content } objects. Content can hold text, image and document blocks, and so can a tool_result, so a tool can return a screenshot. A document can be a text or CSV file of up to 1 MB.
system
string | array
stream
boolean
default: false
true to stream the reply. See Streaming.
tools
array
tool_choice. See Tool calling.
thinking
object
{"type":"enabled"} to have a reasoning model think first, or {"type":"disabled"} to skip it. Add budget_tokens to limit the thinking. The budget comes on top of max_tokens and defaults to 8,192. See Limit how long it thinks.
output_config
object
format to {"type":"json_schema","schema":{...}} for a reply that matches your schema. See Structured output.
temperature, top_p, top_k
number
stop_sequences
array
cache_control
object
Response
You get Anthropic's message object, as in the example.
content holds text, tool_use and
thinking blocks. stop_reason is
end_turn, or max_tokens if the reply was cut off.
A thinking block comes with a signature. Send the
block back unchanged in the next turn, especially after a tool call, so the
model can see its earlier thinking. Pendra's signatures only work on Pendra.
The reply also has a pendra field, which Anthropic clients
ignore:
"pendra": {
"worker": {"id": "wrk-1a2b3c4d", "name": "london-gpu-01", "version": "3.115.1"},
"request_id": "3f1c8a2e-5b7d-4e19-9c0a-6d2f8b1e4a73",
"timing": {"ttft_ms": 115, "tokens_per_second": 58.34, "queue_wait_ms": 16600}
}
workerandrequest_idsay which worker ran it. See Which worker served the request.timinggives the speed. See Timing.noticeexplains an unusual reply, such as thinking that hit its budget. See Notices.images_omittedappears when the oldest images in a long conversation were left out.
A stream carries notice on its last message_delta
event, and names the worker in the X-Worker-Id and
X-Worker-Name headers instead.
Structured output
Set output_config.format to a JSON Schema and the reply is
JSON that matches it. In Python, the Anthropic SDK's
messages.parse() builds the schema from a class for you:
from anthropic import Anthropic
from pydantic import BaseModel
class Person(BaseModel):
name: str
age: int
client = Anthropic(base_url="https://api.pendra.ai", api_key="pdr_sk_...")
message = client.messages.parse(
model="qwen3.6:27b",
max_tokens=512,
messages=[{"role": "user", "content": "Extract the name and age from: Sara is 34."}],
output_format=Person,
)
print(message.parsed_output) # name='Sara' age=34
Only json_schema is supported. Any other format gets a
400.
Prompt caching
Pendra reuses the part of a conversation it has already read, so follow-up turns start replying sooner. It's automatic and free, so you don't need cache breakpoints. You can leave them in, and they're ignored.
usage.cache_read_input_tokensis how many input tokens came from the cache. Divide it byinput_tokensfor the hit rate.cache_creation_input_tokensis always0, because writing to the cache costs nothing.- When streaming, both arrive on the last
message_deltaevent.
Streaming
With "stream": true you get Anthropic's events:
event: message_start
data: {"type":"message_start","message":{"id":"msg_01N3Xc8","type":"message","role":"assistant","content":[],"model":"qwen3.6:27b-q4_k_m","stop_reason":null,"usage":{"input_tokens":9,"output_tokens":0}}}
event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello"}}
event: message_delta
data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":9,"output_tokens":2,"cache_creation_input_tokens":0,"cache_read_input_tokens":0}}
event: message_stop
data: {"type":"message_stop"}
- If the request can't start, for example because no worker is online or every worker is busy, you get a normal HTTP error before any events, so check the status first. See Errors & rate limits.
- A failure after the stream has started arrives as an
errorevent. -
While a long prompt is being read, Pendra sends a
: keep-aliveline every 15 seconds. SDKs ignore it. If you read the stream yourself, skip lines that start with:. - When your workers are busy, Pendra can hold a request for a while before it starts, so give your HTTP client a timeout of at least 90 seconds.
Count tokens
POST /v1/messages/count_tokens takes the same
model, messages and system, and
estimates a prompt's size before you send it:
{ "input_tokens": 1834 }
It's a rough count of the text and any attached files, at about four
characters per token. Images, tools and thinking aren't counted. The exact
figure is in a request's usage once it has run.
Counting reads your prompt, and it can't be encrypted. If your
organisation requires end-to-end encryption, it answers 403
e2e_required.
Use with Claude Code
Claude Code asks for Anthropic's own models by default, such as
claude-sonnet-4-5. Pendra won't swap in a model for a name it
doesn't know, so set a Pendra model id or you'll get a 404.
See Claude Code for the full
setup.