Spaces:
Sleeping
Sleeping
File size: 3,270 Bytes
691a58d 3dac55c 6d5630c 691a58d 6d5630c 691a58d 6d5630c 3dac55c 6d5630c 3dac55c 3d49d68 6d5630c 3dac55c 6d5630c 3dac55c 6d5630c 3dac55c 6d5630c 3dac55c 6d5630c 3d49d68 6d5630c 3dac55c 6d5630c 3dac55c 6d5630c 3dac55c 6d5630c 3d49d68 6d5630c 3d49d68 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | ---
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 |
|