haiku-api / README.md
overwrite69's picture
Upload folder using huggingface_hub
3d49d68 verified
---
title: Haiku API
emoji: 🤖
colorFrom: blue
colorTo: purple
sdk: docker
app_port: 7860
---
# Haiku API
OpenAI-compatible API proxy for Claude Haiku 4.5 via chatgpt.org.
Supports **tool/function calling**, auto-continue for the 1K token limit, rotating proxy, and SSE keep-alive.
## Features
- **Tool/Function Calling**: Full OpenAI-compatible tool calling support. Converts `tools` definitions to system prompts, parses Claude's output for `<tool_call_>` blocks, and returns properly formatted `tool_calls` responses.
- **Auto-Continue**: When the upstream 1K token limit is hit, automatically continues the response with "Continue" messages.
- **SSE Keep-Alive**: Sends keep-alive comments during continuation gaps to prevent socket timeouts.
- **Rotating Proxy**: Supports unstable rotating proxies with automatic retries on connection failures.
- **Message Normalization**: Handles Orchids.app's content array format and converts it to plain text.
## Environment Variables
| Variable | Description | Default |
|---|---|---|
| `PROXY_URL` | Rotating proxy URL (e.g. `http://user:pass@proxy.op.wtf:32424`) | `""` (direct) |
Set these in HF Spaces > Settings > Variables and Secrets.
## Usage
### Chat Completions (non-streaming)
```bash
curl https://YOUR_SPACE.hf.space/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "anthropic/claude-haiku-4-5",
"messages": [{"role": "user", "content": "Hello!"}]
}'
```
### Chat Completions (streaming)
```bash
curl https://YOUR_SPACE.hf.space/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "anthropic/claude-haiku-4-5",
"messages": [{"role": "user", "content": "Hello!"}],
"stream": true
}'
```
### With Tool Calling
```bash
curl https://YOUR_SPACE.hf.space/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "anthropic/claude-haiku-4-5",
"messages": [{"role": "user", "content": "Create a file called hello.txt with hello world"}],
"tools": [{
"type": "function",
"function": {
"name": "Write",
"description": "Write content to a file",
"parameters": {
"type": "object",
"properties": {
"file_path": {"type": "string", "description": "Path to the file"},
"content": {"type": "string", "description": "Content to write"}
},
"required": ["file_path", "content"]
}
}
}]
}'
```
### With OpenAI Python SDK
```python
from openai import OpenAI
client = OpenAI(
base_url="https://YOUR_SPACE.hf.space/v1",
api_key="not-needed",
)
response = client.chat.completions.create(
model="anthropic/claude-haiku-4-5",
messages=[{"role": "user", "content": "Hello!"}],
)
print(response.choices[0].message.content)
```
### List Models
```bash
curl https://YOUR_SPACE.hf.space/v1/models
```
## Endpoints
| Endpoint | Description |
|---|---|
| `POST /v1/chat/completions` | OpenAI-compatible chat completions (with tool calling) |
| `POST /chat/completions` | Same, without /v1 prefix |
| `GET /v1/models` | List available models |
| `GET /health` | Health check |
| `GET /debug/session` | Session debug info |
| `GET /debug/refresh` | Force session refresh |