Skip to content

Commit 4f4efd0

Browse files
committed
Refactoring tests
1 parent 3c022cb commit 4f4efd0

19 files changed

Lines changed: 1102 additions & 314 deletions

README.md

Lines changed: 46 additions & 221 deletions
Original file line numberDiff line numberDiff line change
@@ -1,277 +1,102 @@
11
# Claude Code API Gateway
22

3-
A simple, focused OpenAI-compatible API gateway for Claude Code with streaming support.
4-
Leverage the Claude Code SDK use mode. Don't hack the token credentials.
3+
OpenAI-compatible API gateway for Claude Code CLI.
54

6-
## Getting Started
5+
## What You Get
76

8-
Use the Makefile to install the project or pip/uv.
7+
- OpenAI-style endpoints (`/v1/chat/completions`, `/v1/models`, sessions/projects APIs)
8+
- Streaming and non-streaming chat completions
9+
- Claude model aliases and fallback behavior
10+
- Optional `model` field: if omitted, CLI default model is used
911

10-
![API Started](assets/api.png)
12+
## Quick Start (Linux/macOS)
1113

12-
![Cline use](assets/cline.png)
13-
14-
![Cursor](assets/cursor.png)
15-
16-
![OpenWebUI](assets/openwebui.png)
17-
18-
![Roo Code config](assets/roocode.png)
19-
20-
![Roo Code chat](assets/roo_code.png)
21-
22-
### Python Implementation
2314
```bash
24-
# Clone and setup
2515
git clone https://github.com/codingworkflow/claude-code-api
2616
cd claude-code-api
27-
28-
# Install dependencies & module
29-
make install
30-
31-
# Start the API server
17+
make install
3218
make start
3319
```
3420

35-
## Limitations
36-
37-
- There might be a limit on maximum input below normal "Sonnet 4" input as Claude Code usually doesn't ingest more than 25k tokens (despite the context being 100k).
38-
- Claude Code auto-compacts context beyond 100k.
39-
- Currently runs with bypass mode to avoid tool errors.
40-
- Claude Code tools may need to be disabled to avoid overlap and background usage.
41-
- Runs only on Linux/Mac as Claude Code doesn't run on Windows (you can use WSL).
42-
- Note that Claude Code will default to accessing the current workspace environment/folder and is set to use bypass mode.
43-
44-
45-
## Features
46-
47-
- **Claude-Only Models**: Supports exactly the 4 Claude models that Claude Code CLI offers
48-
- **OpenAI Compatible**: Drop-in replacement for OpenAI API endpoints
49-
- **Streaming Support**: Real-time streaming responses
50-
- **Simple & Clean**: No over-engineering, focused implementation
51-
- **Claude Code Integration**: Leverages Claude Code CLI with streaming output
52-
53-
## Supported Models
54-
55-
Model definitions live in `claude_code_api/config/models.json`.
56-
Override with `CLAUDE_CODE_API_MODELS_PATH` to point at a custom JSON file.
57-
58-
- `claude-opus-4-5-20250929` - Claude Opus 4.5 (Most powerful)
59-
- `claude-sonnet-4-5-20250929` - Claude Sonnet 4.5 (Latest Sonnet)
60-
- `claude-haiku-4-5-20250929` - Claude Haiku 4.5 (Fast & cost-effective)
61-
62-
## Quick Start
21+
Server URLs:
22+
- API: `http://localhost:8000`
23+
- OpenAPI docs: `http://localhost:8000/docs`
24+
- Health: `http://localhost:8000/health`
6325

64-
### Prerequisites
65-
- Python 3.10+
66-
- Claude Code CLI installed and accessible
67-
- Valid Anthropic API key configured in Claude Code (ensure it works in current directory src/)
26+
## Quick Start (Windows)
6827

69-
### Installation & Setup
28+
Use the provided wrappers:
7029

71-
```bash
72-
# Clone and setup
73-
git clone https://github.com/codingworkflow/claude-code-api
74-
cd claude-code-api
75-
76-
# Install dependencies
77-
make install
78-
79-
# Run tests to verify setup
80-
make test
81-
82-
# Start the API server
83-
make start-dev
30+
```bat
31+
make.bat install
32+
start.bat
8433
```
8534

86-
The API will be available at:
87-
- **API**: http://localhost:8000
88-
- **Docs**: http://localhost:8000/docs
89-
- **Health**: http://localhost:8000/health
35+
Notes:
36+
- `start.bat` starts the API in dev mode.
37+
- `make.bat` provides common project commands.
38+
- Claude Code CLI support on Windows may require WSL depending on your local setup.
9039

91-
## Makefile Commands
92-
93-
### Core Commands
94-
```bash
95-
make install # Install production dependencies
96-
make install-dev # Install development dependencies
97-
make test # Run all tests
98-
make start # Start API server (production)
99-
make start-dev # Start API server (development with reload)
100-
```
40+
## Supported Models
10141

102-
### Testing
103-
```bash
104-
make test # Run all tests
105-
make test-fast # Run tests (skip slow ones)
106-
make test-hello # Test hello world with Haiku
107-
make test-health # Test health check only
108-
make test-models # Test models API only
109-
make test-chat # Test chat completions only
110-
make quick-test # Quick validation of core functionality
111-
```
42+
Model config is in `claude_code_api/config/models.json`.
43+
Override with `CLAUDE_CODE_API_MODELS_PATH`.
11244

113-
### Development
114-
```bash
115-
make dev-setup # Complete development setup
116-
make lint # Run linting checks
117-
make format # Format code with black/isort
118-
make type-check # Run type checking
119-
make clean # Clean up cache files
120-
```
45+
- `claude-opus-4-6-20260205`
46+
- `claude-opus-4-5-20251101`
47+
- `claude-sonnet-4-5-20250929`
48+
- `claude-haiku-4-5-20251001`
12149

122-
### Information
123-
```bash
124-
make help # Show all available commands
125-
make models # Show supported Claude models
126-
make info # Show project information
127-
make check-claude # Check if Claude Code CLI is available
128-
```
50+
Alias/fallback behavior:
51+
- `model` is optional in `/v1/chat/completions`.
52+
- `opus`, `claude-opus-latest`, `claude-opus-4-6` resolve to Opus 4.6.
53+
- If Opus 4.6 is rejected at runtime, gateway retries once with latest configured Opus 4.5.
54+
- If all attempted models are rejected, API returns `400` with `error.code = model_not_supported`.
12955

13056
## API Usage
13157

132-
### Chat Completions
58+
Chat completion:
13359

13460
```bash
13561
curl -X POST http://localhost:8000/v1/chat/completions \
13662
-H "Content-Type: application/json" \
13763
-d '{
138-
"model": "claude-sonnet-4-5-20250929",
13964
"messages": [
140-
{"role": "user", "content": "Hello!"}
65+
{"role": "user", "content": "Hello"}
14166
]
14267
}'
14368
```
14469

145-
### List Models
70+
List models:
14671

14772
```bash
14873
curl http://localhost:8000/v1/models
14974
```
15075

151-
### Streaming Chat
76+
Streaming:
15277

15378
```bash
15479
curl -X POST http://localhost:8000/v1/chat/completions \
15580
-H "Content-Type: application/json" \
15681
-d '{
15782
"model": "claude-sonnet-4-5-20250929",
158-
"messages": [
159-
{"role": "user", "content": "Tell me a joke"}
160-
],
83+
"messages": [{"role": "user", "content": "Tell me a joke"}],
16184
"stream": true
16285
}'
16386
```
16487

165-
## Project Structure
166-
167-
```
168-
claude-code-api/
169-
├── claude_code_api/
170-
│ ├── main.py # FastAPI application
171-
│ ├── api/ # API endpoints
172-
│ │ ├── chat.py # Chat completions
173-
│ │ ├── models.py # Models API
174-
│ │ ├── projects.py # Project management
175-
│ │ └── sessions.py # Session management
176-
│ ├── core/ # Core functionality
177-
│ │ ├── auth.py # Authentication
178-
│ │ ├── claude_manager.py # Claude Code integration
179-
│ │ ├── session_manager.py # Session management
180-
│ │ ├── config.py # Configuration
181-
│ │ └── database.py # Database layer
182-
│ ├── models/ # Data models
183-
│ │ ├── claude.py # Claude-specific models
184-
│ │ └── openai.py # OpenAI-compatible models
185-
│ ├── utils/ # Utilities
186-
│ │ ├── streaming.py # Streaming support
187-
│ │ └── parser.py # Output parsing
188-
│ └── tests/ # Test suite
189-
├── Makefile # Development commands
190-
├── pyproject.toml # Project configuration
191-
├── setup.py # Package setup
192-
└── README.md # This file
193-
```
194-
195-
## Testing
196-
197-
The test suite validates:
198-
- Health check endpoints
199-
- Models API (Claude models only)
200-
- Chat completions with Haiku model
201-
- Hello world functionality
202-
- OpenAI compatibility (structure)
203-
- Error handling
204-
205-
Run specific test suites:
206-
```bash
207-
make test-hello # Test hello world with Haiku
208-
make test-models # Test models API
209-
make test-chat # Test chat completions
210-
```
211-
212-
## Development
213-
214-
### Setup Development Environment
215-
```bash
216-
make dev-setup
217-
```
218-
219-
### Code Quality
220-
```bash
221-
make format # Format code
222-
make lint # Check linting
223-
make type-check # Type checking
224-
```
225-
226-
### Quick Validation
227-
```bash
228-
make quick-test # Test core functionality
229-
```
230-
231-
## Deployment
232-
233-
### Check Deployment Readiness
234-
```bash
235-
make deploy-check
236-
```
237-
238-
### Production Server
239-
```bash
240-
make start-prod # Start with multiple workers
241-
```
242-
Use http://127.0.0.1:8000/v1 as OpenAPI endpoint
243-
24488
## Configuration
24589

246-
Key settings in `claude_code_api/core/config.py`:
247-
- `claude_binary_path`: Path to Claude Code CLI
248-
- `project_root`: Root directory for projects
249-
- `database_url`: Database connection string
250-
- `require_auth`: Enable/disable authentication
251-
252-
## Design Principles
253-
254-
1. **Simple & Focused**: No over-engineering
255-
2. **Claude-Only**: Pure Claude gateway, no OpenAI models
256-
3. **Streaming First**: Built for real-time streaming
257-
4. **OpenAI Compatible**: Drop-in API compatibility
258-
5. **Test-Driven**: Comprehensive test coverage
90+
Common settings are in `claude_code_api/core/config.py`:
91+
- `claude_binary_path`
92+
- `project_root`
93+
- `database_url`
94+
- `require_auth`
25995

260-
## Health Check
96+
## Developer Docs
26197

262-
```bash
263-
curl http://localhost:8000/health
264-
```
265-
266-
Response:
267-
```json
268-
{
269-
"status": "healthy",
270-
"version": "1.0.0",
271-
"claude_version": "1.x.x",
272-
"active_sessions": 0
273-
}
274-
```
98+
For engineering workflows and internal commands:
99+
- `docs/dev.md`
275100

276101
## License
277102

0 commit comments

Comments
 (0)