Anthropic Compatibility
Use the Anthropic SDK against Ablatic
Point the official Anthropic SDK at Ablatic and keep your code. The /v1/messages endpoint is a drop-in for the Anthropic Messages API.
What to change
- Set
base_urltohttps://api.ablatic.ai. - Authenticate with the
x-api-keyheader, set to yoursk-ablatic-...key. The SDK sends this header for you. - Call the
/v1/messagesendpoint, which the SDK targets by default.
The anthropic-version header is accepted. The SDK sets it automatically, so you do not need to add it.
Python
from anthropic import Anthropic
client = Anthropic(
base_url="https://api.ablatic.ai",
api_key="sk-ablatic-...",
)
resp = client.messages.create(
model="talos",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello"}],
)
print(resp.content[0].text)max_tokens is required on this surface. The Anthropic Messages API requires it, so a request without it is rejected.
Streaming
Set stream=True and read the named SSE events that the Anthropic API uses: message_start, then content_block_start, content_block_delta, content_block_stop, then message_delta and message_stop. There is no data: [DONE] line on this surface.
with client.messages.stream(
model="talos",
max_tokens=1024,
messages=[{"role": "user", "content": "Write a haiku about Linz"}],
) as stream:
for text in stream.text_stream:
print(text, end="")Documents
Attach a PDF with Anthropic's document block. Nothing gets stored, and you skip the upload step.
import base64
pdf = base64.standard_b64encode(open("report.pdf", "rb").read()).decode()
msg = client.messages.create(
model="talos",
max_tokens=1024,
messages=[{
"role": "user",
"content": [
{"type": "document", "source": {
"type": "base64", "media_type": "application/pdf", "data": pdf,
}},
{"type": "text", "text": "What is the invoice total?"},
],
}],
)A PDF with a text layer gets extracted as text, up to 200,000 characters. A scan or photo PDF gets rendered to page images and read by the vision model: 20 pages at most. Files covers both paths and the mixed-PDF caveat.
source.type also accepts "text" for a plain-text document. A "url" source never gets fetched, and the request still returns 200: Talos tells the model that the URL was not resolved, so the answer comes back without the document. Download the file yourself and send the bytes.
Caveats specific to this surface
Read these before you port options over from the Anthropic API.
- Structured outputs are not available here.
response_formatis not honored on/v1/messages. Use the OpenAI-style surface for JSON mode. See OpenAI compatibility. stop_sequencesare accepted but ignored. Do not rely on them to cut generation.- Prompt caching is real and billed. The server caches prompt prefixes automatically, and
cache_controlmarks which prefixes to prime and shapes the usage breakdown to match the Anthropic format. Cached reads cost a fraction of the input rate; the first write is billed at the normal input rate, with no premium. See Usage and billing. - Prior
thinkingblocks are dropped. Earlier reasoning content is not carried back into a follow-up request.