mirror of
https://github.com/hanzo-docs/docs.git
synced 2026-10-28 07:09:50 +00:00
Cloud verifies two key shapes, pk- and sk-, and IAM has minted sk- since v1.33.9. Nothing mints hk-, so every curl, env var and SDK snippet carrying it handed the reader a credential that resolves to no principal. Server-side examples become sk-. The one publishable case is the Console tracing client, whose constructor field is publicKey; that becomes pk-. Where a page taught the taxonomy rather than just used it, the prose is rewritten rather than character-swapped. api-keys and getting-started listed "API Key (hk-)" and "Secret Key (sk-)" as two prefixes; after the retirement that is one row, and scope -- not prefix -- is what separates a project key from an org key. apps/spec is generated from hanzoai/HIPs, which carried the same claim; fixed there. The vendored openapi document has no hk-, so the pin is untouched.
150 lines
3.6 KiB
Plaintext
150 lines
3.6 KiB
Plaintext
---
|
|
title: Messages (Anthropic-compatible)
|
|
description: Use the Anthropic Messages API format with Zen models via api.hanzo.ai
|
|
---
|
|
|
|
# Messages API (Anthropic-compatible)
|
|
|
|
Zen models are reachable through the **Anthropic Messages wire format** at the
|
|
same base URL, alongside the chat-completions format. This is a second envelope
|
|
we speak so that a client already written against that shape can call Zen models
|
|
without being rewritten — point its base URL at `https://api.hanzo.ai/v1` and
|
|
give it a Hanzo key. Model ids do not carry across vendors: the ids below are
|
|
Hanzo models and resolve only here.
|
|
|
|
## Endpoint
|
|
|
|
```
|
|
POST https://api.hanzo.ai/v1/messages
|
|
```
|
|
|
|
## Authentication
|
|
|
|
```bash
|
|
x-api-key: $HANZO_API_KEY
|
|
# or
|
|
Authorization: Bearer $HANZO_API_KEY
|
|
```
|
|
|
|
Include the `anthropic-version` header:
|
|
|
|
```bash
|
|
anthropic-version: 2023-06-01
|
|
```
|
|
|
|
## Quickstart
|
|
|
|
### curl
|
|
|
|
```bash
|
|
curl https://api.hanzo.ai/v1/messages \
|
|
-H "x-api-key: $HANZO_API_KEY" \
|
|
-H "anthropic-version: 2023-06-01" \
|
|
-H "Content-Type: application/json" \
|
|
-d '{
|
|
"model": "zen5",
|
|
"max_tokens": 1024,
|
|
"messages": [{"role": "user", "content": "Hello, Zen."}]
|
|
}'
|
|
```
|
|
|
|
### Python (Anthropic SDK)
|
|
|
|
```python
|
|
from anthropic import Anthropic
|
|
|
|
client = Anthropic(
|
|
api_key="sk-your-api-key",
|
|
base_url="https://api.hanzo.ai/v1",
|
|
)
|
|
|
|
message = client.messages.create(
|
|
model="zen5",
|
|
max_tokens=1024,
|
|
messages=[{"role": "user", "content": "Hello, Zen."}],
|
|
)
|
|
print(message.content[0].text)
|
|
```
|
|
|
|
### TypeScript (Anthropic SDK)
|
|
|
|
```typescript
|
|
import Anthropic from "@anthropic-ai/sdk";
|
|
|
|
const client = new Anthropic({
|
|
apiKey: "sk-your-api-key",
|
|
baseURL: "https://api.hanzo.ai/v1",
|
|
});
|
|
|
|
const message = await client.messages.create({
|
|
model: "zen5",
|
|
max_tokens: 1024,
|
|
messages: [{ role: "user", content: "Hello, Zen." }],
|
|
});
|
|
console.log(message.content[0].text);
|
|
```
|
|
|
|
## Streaming
|
|
|
|
```bash
|
|
curl https://api.hanzo.ai/v1/messages \
|
|
-H "x-api-key: $HANZO_API_KEY" \
|
|
-H "anthropic-version: 2023-06-01" \
|
|
-H "Content-Type: application/json" \
|
|
-d '{
|
|
"model": "zen5",
|
|
"max_tokens": 1024,
|
|
"stream": true,
|
|
"messages": [{"role": "user", "content": "Hello, Zen."}]
|
|
}'
|
|
```
|
|
|
|
Streaming uses Server-Sent Events (SSE), identical to the Anthropic streaming format.
|
|
|
|
## Supported Parameters
|
|
|
|
| Parameter | Type | Required | Description |
|
|
|-----------|------|----------|-------------|
|
|
| `model` | string | Yes | Zen model ID (e.g., `zen5`, `zen5-pro`, `zen5-coder`) |
|
|
| `messages` | array | Yes | Array of message objects with `role` and `content` |
|
|
| `max_tokens` | integer | Yes | Maximum tokens to generate |
|
|
| `stream` | boolean | No | Enable SSE streaming (default: false) |
|
|
| `temperature` | float | No | Sampling temperature (0.0 - 1.0) |
|
|
| `top_p` | float | No | Nucleus sampling parameter |
|
|
| `system` | string | No | System prompt |
|
|
| `stop_sequences` | array | No | Stop generation at these sequences |
|
|
|
|
## Response Format
|
|
|
|
```json
|
|
{
|
|
"id": "msg_abc123",
|
|
"type": "message",
|
|
"role": "assistant",
|
|
"content": [
|
|
{
|
|
"type": "text",
|
|
"text": "Hello! How can I help you today?"
|
|
}
|
|
],
|
|
"model": "zen5",
|
|
"stop_reason": "end_turn",
|
|
"usage": {
|
|
"input_tokens": 12,
|
|
"output_tokens": 15
|
|
}
|
|
}
|
|
```
|
|
|
|
## Using Both Formats
|
|
|
|
The same `api.hanzo.ai/v1` host serves both wire formats:
|
|
|
|
| Wire format | Endpoint | Clients |
|
|
|-------------|----------|---------|
|
|
| Chat completions | `POST /v1/chat/completions` | `hanzoai`, `@hanzo/ai`, or any client written for that shape |
|
|
| Messages | `POST /v1/messages` | `anthropic` |
|
|
| Catalogue | `GET /v1/models` | Any HTTP client |
|
|
|
|
All Zen models work with both. Use whichever your application already speaks.
|