Simple HTTP API server for Claude, distributed as a Docker container.
curl -sSL https://raw.githubusercontent.com/zenjabba/claude-agent-api/main/install.sh | bash
curl -sSL https://raw.githubusercontent.com/zenjabba/claude-agent-api/main/install.sh | bash
cd claude-agent-api
Get your Claude OAuth token:
# Install Claude CLI (if not already installed)
npm install -g @anthropic-ai/claude-code
# Generate OAuth token
claude setup-token
Create .env file with your token:
echo "CLAUDE_CODE_OAUTH_TOKEN=sk-ant-oat01-your-token-here" > .env
docker-compose up -d
docker-compose exec claude-agent python3 manage_keys.py create "my-app"
This will output your API key:
API Key created successfully!
Name: my-app
Key: sk-xnavTWseV_vPyi9HtAnpJ9KQ1o4mb9hgNU0zkFKMXH4
Keep this key secure - it won't be shown again!
curl http://localhost:8787/health
Response:
{
"status": "healthy",
"hasToken": true,
"timestamp": "2025-10-18T01:54:45.806285"
}
Basic Query (uses default model: claude-haiku-4-5):
curl -X POST http://localhost:8787/query \
-H "Content-Type: application/json" \
-d '{
"query": "What is the meaning of life?",
"api_key": "sk-your-api-key-here"
}'
Response:
{
"response": "The meaning of life is a philosophical question..."
}
Query with Custom Model:
curl -X POST http://localhost:8787/query \
-H "Content-Type: application/json" \
-d '{
"query": "Write a Python function to calculate fibonacci",
"model": "claude-sonnet-4-5",
"api_key": "sk-your-api-key-here"
}'
Available Models:
claude-haiku-4-5 (default - fastest, cheapest)claude-sonnet-4-5 (balanced)claude-opus-4 (most capable)claude-3-5-sonnet-20241022claude-3-5-haiku-20241022Missing API Key (401):
{
"error": "API key required",
"message": "Include \"api_key\" in request body"
}
Invalid API Key (403):
{
"error": "Invalid API key"
}
No Query (400):
{
"error": "No prompt provided"
}
docker-compose exec claude-agent python3 manage_keys.py create "my-app-name"
docker-compose exec claude-agent python3 manage_keys.py list
Output:
API Key Name Created Last Used
------------------------------------------------------------------------------------------------------------------------
sk-xnavTWs...zkFKMXH4 my-app 2025-10-18T01:54:46.329585 2025-10-18T01:54:58.066326
Total: 1 API key(s)
docker-compose exec claude-agent python3 manage_keys.py delete sk-xnavTWseV_vPyi9HtAnpJ9KQ1o4mb9hgNU0zkFKMXH4
services:
claude-agent:
build: .
container_name: claude-agent-api
ports:
- "8787:8787"
volumes:
- claude-data:/data
env_file:
- .env
environment:
- PORT=8787
restart: unless-stopped
volumes:
claude-data:
Create a .env file:
CLAUDE_CODE_OAUTH_TOKEN=sk-ant-oat01-your-token-here
PORT=8787
API keys are stored in /data/api_keys.json (persisted in Docker volume)
Default model can be changed by creating /data/.config.json:
{
"default_model": "claude-sonnet-4-5"
}
# Pull latest code
git pull
# Rebuild and restart
docker-compose build
docker-compose up -d
import requests
api_key = "sk-your-api-key-here"
url = "http://localhost:8787/query"
response = requests.post(url, json={
"query": "What is 2+2?",
"api_key": api_key
})
print(response.json()["response"])
const response = await fetch('http://localhost:8787/query', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
query: 'What is 2+2?',
api_key: 'sk-your-api-key-here'
})
});
const data = await response.json();
console.log(data.response);
curl -X POST http://localhost:8787/query \
-H "Content-Type: application/json" \
-d '{
"query": "What is 2+2?",
"api_key": "sk-your-api-key-here"
}'
/data/api_keys.jsonCheck logs:
docker-compose logs
OAuth tokens are managed automatically by Claude CLI and should not expire. If you see authentication errors:
.envdocker-compose restart
If issues persist, regenerate the token:
claude setup-token
# Update .env file with new token
docker-compose restart
List existing keys:
docker-compose exec claude-agent python3 manage_keys.py list
Create new key if needed:
docker-compose exec claude-agent python3 manage_keys.py create "new-key"
MIT
Content type
Image
Digest
sha256:de80e5497…
Size
296.1 MB
Last updated
12 months ago
docker pull zenjabba/claude-agent-api