A lightweight Python proxy that enables Claude Code to work with REDCap's SecureChatAI External Module by translating between Claude's API format and REDCap's API format.
✅ Zero-buffering SSE streaming - Instant response delivery
✅ 100% vanilla Python - No dependencies, just standard library
✅ Docker support - Easy deployment with Docker Compose
✅ Model mapping - Automatically maps Claude model names to SecureChatAI aliases
✅ Full Claude API compatibility - Works seamlessly with Claude Code
git clone git@github.com:susom/claude_proxy.git
cd claude-code-proxycp .env.example .envEdit .env with your REDCap credentials:
REDCAP_API_URL=http://your-redcap-server.com/api/
REDCAP_API_TOKEN=your_redcap_api_token_here
LISTEN_HOST=localhost
LISTEN_PORT=8765docker compose up -dThe proxy will be available at http://localhost:8765.
Set these environment variables in your shell:
export ANTHROPIC_AUTH_TOKEN="your_redcap_api_token_here"
export ANTHROPIC_BASE_URL="http://localhost:8765"Then launch Claude Code and start chatting!
Claude Code → Proxy (localhost:8765) → REDCap SecureChatAI → AI Models
The proxy:
- Receives Claude API requests from Claude Code
- Translates them to REDCap External Module API format
- Forwards to your REDCap SecureChatAI instance
- Streams responses back to Claude Code via Server-Sent Events (SSE)
The proxy automatically maps Claude model names to SecureChatAI model aliases:
| Claude Model | SecureChatAI Alias |
|---|---|
claude-haiku-4-5-20251001 |
gpt-4o |
claude-3-7-sonnet-20250219 |
claude |
claude-sonnet-4 |
claude |
o3-mini |
o3-mini |
o1 |
o1 |
gpt-4.1 |
gpt-4.1 |
deepseek |
deepseek |
You can customize these mappings in claude_api_proxy.py.
If you prefer to run the proxy directly:
# Set environment variables
export REDCAP_API_URL="http://your-redcap-server.com/api/"
export REDCAP_API_TOKEN="your_token"
export LISTEN_HOST="localhost"
export LISTEN_PORT="8765"
# Run the proxy
python3 claude_api_proxy.py- Check proxy logs:
docker compose logs -f - Verify environment variables are set correctly
- Ensure REDCap API URL is accessible from the proxy
- Restart Claude Code after changing proxy settings
- The proxy uses zero-buffering SSE streaming for instant delivery
- Delays are likely from the upstream AI model, not the proxy
- Check REDCap SecureChatAI logs for performance issues
- Verify
REDCAP_API_TOKENmatches your REDCap token - Ensure the token has access to the SecureChatAI module
- Check that
ANTHROPIC_AUTH_TOKENin Claude Code matches the REDCap token
- UnbufferedHTTPRequestHandler: Custom HTTP handler with
wbufsize=0to disable buffering - SSE Streaming: Implements Anthropic's 6-event SSE sequence:
message_startcontent_block_startcontent_block_delta(text content)content_block_stopmessage_delta(usage stats)message_stop
wbufsize = 0on request handlerwfile.flush()after every SSE eventTransfer-Encoding: chunkedheaderX-Accel-Buffering: noheader (for nginx)- Socket-level TCP_CORK disabled
- No additional authentication beyond token validation
- Runs on localhost by default
- Use VPN or firewall rules if exposing to network
- Keep your
.envfile secure and never commit it to git
claude-code-proxy/
├── claude_api_proxy.py # Main proxy server
├── Dockerfile # Docker image definition
├── docker-compose.yml # Docker Compose configuration
├── .env.example # Example environment variables
├── .gitignore # Git ignore rules
└── README.md # This file
- Edit
claude_api_proxy.py - Rebuild Docker image:
docker compose build - Restart:
docker compose up -d