| 中文 | English |
This guide provides detailed instructions for installing and configuring Claude Code Adapter FastAPI.
We provide intelligent setup scripts that support multiple environment management methods:
# Clone the repository
git clone https://github.com/wangfumin1/claude-code-adapter-fastapi.git
cd claude-code-adapter-fastapi
# Using venv (default)
scripts\setup.bat
# Using conda
scripts\setup.bat --env conda
# Force reinstall
scripts\setup.bat --force
# Clone the repository
git clone https://github.com/wangfumin1/claude-code-adapter-fastapi.git
cd claude-code-adapter-fastapi
# Using venv (default)
./scripts/setup.sh
# Using conda
./scripts/setup.sh --env conda
# Force reinstall
./scripts/setup.sh --force
If the automated scripts are not suitable, you can set up manually:
Using venv (Recommended):
# Create virtual environment
python -m venv venv
# Activate virtual environment
# Windows:
venv\Scripts\activate
# macOS/Linux:
source venv/bin/activate
Using conda:
# Create conda environment
conda create -n claude-adapter python=3.11
# Activate environment
conda activate claude-adapter
Using virtualenv:
# Install virtualenv
pip install virtualenv
# Create virtual environment
virtualenv venv
# Activate virtual environment
# Windows:
venv\Scripts\activate
# macOS/Linux:
source venv/bin/activate
Using poetry:
# Install poetry
curl -sSL https://install.python-poetry.org | python3 -
# Create project environment
poetry install
# Activate environment
poetry shell
# Production dependencies
pip install -r requirements.txt
# Development dependencies (includes testing and development tools)
pip install -r requirements-dev.txt
The project supports multiple configuration methods, prioritized as follows:
config.yaml)Edit the config.yaml file:
# Target service configuration
target_base_url: "http://127.0.0.1:1234"
target_api_key: "your-api-key"
target_api_key_header: "Authorization"
# Service configuration
host: "127.0.0.1"
port: 8000
debug: false
log_level: "INFO"
You can also configure via environment variables:
export TARGET_BASE_URL="http://your-target-service:1234"
export TARGET_API_KEY="your-api-key"
export HOST="0.0.0.0"
export PORT="8000"
# Important: Client configuration
# In the client, set ANTHROPIC_BASE_URL to point to this service
export ANTHROPIC_BASE_URL="http://localhost:8000"
python -m uvicorn src.claude_code_adapter.app:app --host 0.0.0.0 --port 8000 --reload
python -m uvicorn src.claude_code_adapter.app:app --host 0.0.0.0 --port 8000
python scripts/start.py
curl http://localhost:8000/health
Expected response:
{
"ok": true,
"target_base": "http://127.0.0.1:1234"
}
Access the API documentation at:
docker build -t claude-code-adapter .
docker run -p 8000:8000 -v $(pwd)/config.yaml:/app/config.yaml claude-code-adapter
docker-compose up -d
curl -X POST "http://localhost:8000/v1/messages" \
-H "Content-Type: application/json" \
-d '{
"model": "test-model",
"messages": [
{
"role": "user",
"content": "Hello, how are you?"
}
]
}'
curl -X POST "http://localhost:8000/v1/messages" \
-H "Content-Type: application/json" \
-d '{
"model": "test-model",
"messages": [
{
"role": "user",
"content": "What is the weather like?"
}
],
"tools": [
{
"name": "get_weather",
"description": "Get current weather information",
"input_schema": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city name"
}
},
"required": ["location"]
}
}
]
}'
# Check port usage
netstat -tulpn | grep :8000
# Or use a different port
python -m uvicorn src.claude_code_adapter.app:app --port 8001
config.yaml is in the project root directorytarget_base_url configurationSet a more detailed log level:
log_level: "DEBUG"
Or via environment variable:
export LOG_LEVEL=DEBUG
📝 Related Documentation: If you encounter issues, refer to the Troubleshooting section or the debugging section in the Development Guide.