|
| 1 | +--- |
| 2 | +title: 'Claude Code' |
| 3 | +description: 'Integrate Portkey with Claude Code for enterprise-grade AI coding assistance with observability and governance' |
| 4 | +--- |
| 5 | + |
| 6 | +Claude Code is Anthropic's agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster through natural language commands. |
| 7 | + |
| 8 | +With Portkey integration, you can enhance Claude Code with enterprise features: |
| 9 | + |
| 10 | +- **Unified AI Gateway** - Route Claude Code through multiple providers (Anthropic, Bedrock, Vertex AI) with automatic failover |
| 11 | +- **Centralized Observability** - Track all Claude Code interactions, costs, and performance metrics |
| 12 | +- **Security & Governance** - Set budget limits, implement access controls, and audit all AI usage |
| 13 | +- **Advanced Routing** - Use fallbacks, load balancing, and conditional routing for reliability |
| 14 | + |
| 15 | +<Note> |
| 16 | + This integration uses Portkey's Gateway Passthrough feature. Advanced Portkey capabilities - such as cost calculation, reliability features, and more are not supported yet. |
| 17 | +</Note> |
| 18 | + |
| 19 | +# 1. Setting up Portkey |
| 20 | + |
| 21 | +Before integrating with Claude Code, you'll need to set up the core Portkey components. |
| 22 | + |
| 23 | +<Steps> |
| 24 | +<Step title="Create Virtual Key"> |
| 25 | +Virtual Keys securely manage your LLM provider API keys with built-in controls: |
| 26 | +- Budget limits and rate limiting |
| 27 | +- Secure credential storage |
| 28 | +- Provider switching without code changes |
| 29 | + |
| 30 | +To create a virtual key: |
| 31 | +1. Go to [Virtual Keys](https://app.portkey.ai/virtual-keys) in Portkey |
| 32 | +2. Add your provider (Anthropic, Bedrock, or Vertex AI) credentials |
| 33 | +3. Save and copy the virtual key ID |
| 34 | + |
| 35 | +<Frame> |
| 36 | +<img src="/images/integrations/openai/virtual-key-2.png" width="500"/> |
| 37 | +</Frame> |
| 38 | + |
| 39 | +<Note> |
| 40 | +Save your virtual key ID - you'll need it for Claude Code configuration. |
| 41 | +</Note> |
| 42 | +</Step> |
| 43 | + |
| 44 | +<Step title="Create Config (Optional)"> |
| 45 | +Configs enable advanced routing features. You can either use a virtual key directly or create a config for more control. |
| 46 | + |
| 47 | +To create a config: |
| 48 | +1. Go to [Configs](https://app.portkey.ai/configs) in Portkey |
| 49 | +2. Create new config: |
| 50 | + ```json |
| 51 | + { |
| 52 | + "virtual_key": "YOUR_VIRTUAL_KEY_ID", |
| 53 | + "override_params": { |
| 54 | + "model": "us.anthropic.claude-sonnet-4-20250514-v1:0" |
| 55 | + } |
| 56 | + } |
| 57 | + ``` |
| 58 | +3. Save and note the Config ID |
| 59 | + |
| 60 | +<Note> |
| 61 | +Configs are optional but recommended for production deployments with fallbacks and load balancing. |
| 62 | +</Note> |
| 63 | +</Step> |
| 64 | + |
| 65 | +<Step title="Get Your Portkey API Key"> |
| 66 | +1. Go to [API Keys](https://app.portkey.ai/api-keys) in Portkey |
| 67 | +2. Create or copy your existing API key |
| 68 | +3. Keep it ready for the next steps |
| 69 | +</Step> |
| 70 | +</Steps> |
| 71 | + |
| 72 | +# 2. Integrate Portkey with Claude Code |
| 73 | + |
| 74 | +Claude Code uses a `settings.json` file for configuration. You'll need to modify the environment variables to route requests through Portkey. |
| 75 | + |
| 76 | +<Info> |
| 77 | +For more details on Claude Code proxy configuration, see [Anthropic's documentation](https://docs.anthropic.com/en/docs/claude-code/bedrock-vertex-proxies). |
| 78 | +</Info> |
| 79 | + |
| 80 | +<Tabs> |
| 81 | +<Tab title="Amazon Bedrock"> |
| 82 | +Edit your Claude Code settings file (`~/.claude/settings.json` for global or `.claude/settings.json` in your project): |
| 83 | + |
| 84 | +```json |
| 85 | +{ |
| 86 | + "env": { |
| 87 | + "ANTHROPIC_BEDROCK_BASE_URL": "https://api.portkey.ai/v1", |
| 88 | + "ANTHROPIC_CUSTOM_HEADERS": "x-portkey-api-key: YOUR_PORTKEY_API_KEY\nx-portkey-provider: bedrock\nx-portkey-virtual-key: YOUR_VIRTUAL_KEY", |
| 89 | + "ANTHROPIC_MODEL": "us.anthropic.claude-sonnet-4-20250514-v1:0", |
| 90 | + "CLAUDE_CODE_SKIP_BEDROCK_AUTH": 1, |
| 91 | + "CLAUDE_CODE_USE_BEDROCK": 1 |
| 92 | + } |
| 93 | +} |
| 94 | +``` |
| 95 | + |
| 96 | +<Note> |
| 97 | +The `CLAUDE_CODE_SKIP_BEDROCK_AUTH` and `CLAUDE_CODE_USE_BEDROCK` must be set as numbers (not strings). |
| 98 | +</Note> |
| 99 | + |
| 100 | +Replace: |
| 101 | +- `YOUR_PORTKEY_API_KEY` with your Portkey API key |
| 102 | +- `YOUR_VIRTUAL_KEY` with the virtual key ID from Step 1 |
| 103 | +- Update the model name if using a different Claude model |
| 104 | +</Tab> |
| 105 | + |
| 106 | +<Tab title="Google Vertex AI"> |
| 107 | +For Vertex AI integration: |
| 108 | + |
| 109 | +```json |
| 110 | +{ |
| 111 | + "env": { |
| 112 | + "ANTHROPIC_VERTEX_BASE_URL": "https://api.portkey.ai/v1", |
| 113 | + "ANTHROPIC_CUSTOM_HEADERS": "x-portkey-api-key: YOUR_PORTKEY_API_KEY\nx-portkey-provider: vertex-ai\nx-portkey-virtual-key: YOUR_VIRTUAL_KEY", |
| 114 | + "ANTHROPIC_MODEL": "claude-3-7-sonnet@20250219", |
| 115 | + "CLAUDE_CODE_SKIP_VERTEX_AUTH": 1, |
| 116 | + "CLAUDE_CODE_USE_VERTEX": 1 |
| 117 | + } |
| 118 | +} |
| 119 | +``` |
| 120 | + |
| 121 | +<Note> |
| 122 | +Use `ANTHROPIC_VERTEX_BASE_URL` specifically for Vertex AI, not the generic base URL. |
| 123 | +</Note> |
| 124 | +</Tab> |
| 125 | + |
| 126 | +<Tab title="Anthropic API"> |
| 127 | +For direct Anthropic API usage: |
| 128 | + |
| 129 | +```json |
| 130 | +{ |
| 131 | + "env": { |
| 132 | + "ANTHROPIC_BASE_URL": "https://api.portkey.ai/v1", |
| 133 | + "ANTHROPIC_CUSTOM_HEADERS": "x-portkey-api-key: YOUR_PORTKEY_API_KEY\nx-portkey-provider: anthropic\nx-portkey-virtual-key: YOUR_VIRTUAL_KEY", |
| 134 | + "ANTHROPIC_MODEL": "claude-sonnet-4-20250514" |
| 135 | + } |
| 136 | +} |
| 137 | +``` |
| 138 | +</Tab> |
| 139 | + |
| 140 | +<Tab title="Using Config"> |
| 141 | +If you created a Portkey config for any provider: |
| 142 | + |
| 143 | +```json |
| 144 | +{ |
| 145 | + "env": { |
| 146 | + "ANTHROPIC_BEDROCK_BASE_URL": "https://api.portkey.ai/v1", |
| 147 | + "ANTHROPIC_CUSTOM_HEADERS": "x-portkey-api-key: YOUR_PORTKEY_API_KEY\nx-portkey-config: YOUR_CONFIG_ID", |
| 148 | + "ANTHROPIC_MODEL": "us.anthropic.claude-sonnet-4-20250514-v1:0", |
| 149 | + "CLAUDE_CODE_SKIP_BEDROCK_AUTH": 1, |
| 150 | + "CLAUDE_CODE_USE_BEDROCK": 1 |
| 151 | + } |
| 152 | +} |
| 153 | +``` |
| 154 | + |
| 155 | +<Note> |
| 156 | +When using a config, Portkey will use the provider settings defined in your config. |
| 157 | +</Note> |
| 158 | +</Tab> |
| 159 | +</Tabs> |
| 160 | + |
| 161 | +## Complete Configuration Example |
| 162 | + |
| 163 | +Here's a full `settings.json` example with permissions and Bedrock configuration: |
| 164 | + |
| 165 | +```json |
| 166 | +{ |
| 167 | + "permissions": { |
| 168 | + "allow": [ |
| 169 | + "Bash(npm run lint)", |
| 170 | + "Bash(npm run test:*)", |
| 171 | + "Read(~/.zshrc)" |
| 172 | + ], |
| 173 | + "deny": [ |
| 174 | + "Bash(curl:*)" |
| 175 | + ] |
| 176 | + }, |
| 177 | + "env": { |
| 178 | + "ANTHROPIC_BEDROCK_BASE_URL": "https://api.portkey.ai/v1", |
| 179 | + "ANTHROPIC_CUSTOM_HEADERS": "x-portkey-api-key: YOUR_PORTKEY_API_KEY\nx-portkey-provider: bedrock\nx-portkey-virtual-key: YOUR_VIRTUAL_KEY", |
| 180 | + "ANTHROPIC_MODEL": "us.anthropic.claude-sonnet-4-20250514-v1:0", |
| 181 | + "CLAUDE_CODE_SKIP_BEDROCK_AUTH": 1, |
| 182 | + "CLAUDE_CODE_USE_BEDROCK": 1 |
| 183 | + } |
| 184 | +} |
| 185 | +``` |
| 186 | + |
| 187 | +## Adding Custom Metadata |
| 188 | + |
| 189 | +Track Claude Code usage by team, project, or user: |
| 190 | + |
| 191 | +```json |
| 192 | +{ |
| 193 | + "env": { |
| 194 | + "ANTHROPIC_BEDROCK_BASE_URL": "https://api.portkey.ai/v1", |
| 195 | + "ANTHROPIC_CUSTOM_HEADERS": "x-portkey-api-key: YOUR_PORTKEY_API_KEY\nx-portkey-config: YOUR_CONFIG_ID\nx-portkey-metadata: {\"_user\": \"john.doe\", \"team\": \"engineering\", \"project\": \"backend-api\"}", |
| 196 | + "CLAUDE_CODE_SKIP_BEDROCK_AUTH": 1, |
| 197 | + "CLAUDE_CODE_USE_BEDROCK": 1 |
| 198 | + } |
| 199 | +} |
| 200 | +``` |
| 201 | + |
| 202 | +## Verifying the Integration |
| 203 | + |
| 204 | +After configuring, test Claude Code: |
| 205 | + |
| 206 | +```bash |
| 207 | +# Start Claude Code |
| 208 | +claude |
| 209 | + |
| 210 | +# Ask it to perform a task |
| 211 | +> explain the authentication flow in this codebase |
| 212 | +``` |
| 213 | + |
| 214 | +You should see: |
| 215 | +1. Claude Code functioning normally in your terminal |
| 216 | +2. Requests appearing in your [Portkey logs](https://app.portkey.ai/logs) |
| 217 | +3. Metrics updating in your [Portkey dashboard](https://app.portkey.ai/dashboard) |
| 218 | + |
| 219 | +# 3. Set Up Enterprise Governance for Claude Code |
| 220 | + |
| 221 | +When deploying Claude Code across your organization, implement these governance controls: |
| 222 | + |
| 223 | +<AccordionGroup> |
| 224 | +<Accordion title="Team-Based Access Control"> |
| 225 | +Create separate virtual keys for each team with specific limits: |
| 226 | + |
| 227 | +1. **Engineering Team** |
| 228 | + - Budget: $500/month |
| 229 | + - Models: Claude Sonnet only |
| 230 | + - Rate limit: 100 requests/minute |
| 231 | + |
| 232 | +2. **Data Science Team** |
| 233 | + - Budget: $1000/month |
| 234 | + - Models: All Claude models |
| 235 | + - Rate limit: 200 requests/minute |
| 236 | + |
| 237 | +Deploy team-specific `settings.json` through your configuration management: |
| 238 | + |
| 239 | +```json |
| 240 | +{ |
| 241 | + "env": { |
| 242 | + "ANTHROPIC_BEDROCK_BASE_URL": "https://api.portkey.ai/v1", |
| 243 | + "ANTHROPIC_CUSTOM_HEADERS": "x-portkey-api-key: TEAM_PORTKEY_API_KEY\nx-portkey-virtual-key: TEAM_VIRTUAL_KEY", |
| 244 | + "ANTHROPIC_MODEL": "us.anthropic.claude-sonnet-4-20250514-v1:0", |
| 245 | + "CLAUDE_CODE_SKIP_BEDROCK_AUTH": 1, |
| 246 | + "CLAUDE_CODE_USE_BEDROCK": 1 |
| 247 | + } |
| 248 | +} |
| 249 | +``` |
| 250 | +</Accordion> |
| 251 | + |
| 252 | +<Accordion title="Centralized Policy Management"> |
| 253 | +For enterprise deployments, use policy files to enforce settings: |
| 254 | + |
| 255 | +**macOS**: `/Library/Application Support/ClaudeCode/policies.json` |
| 256 | +**Linux/WSL**: `/etc/claude-code/policies.json` |
| 257 | + |
| 258 | +Example policy file: |
| 259 | +```json |
| 260 | +{ |
| 261 | + "env": { |
| 262 | + "ANTHROPIC_BEDROCK_BASE_URL": "https://api.portkey.ai/v1", |
| 263 | + "ANTHROPIC_CUSTOM_HEADERS": "x-portkey-api-key: ENTERPRISE_API_KEY\nx-portkey-config: ENTERPRISE_CONFIG_ID", |
| 264 | + "CLAUDE_CODE_SKIP_BEDROCK_AUTH": 1, |
| 265 | + "CLAUDE_CODE_USE_BEDROCK": 1 |
| 266 | + }, |
| 267 | + "permissions": { |
| 268 | + "deny": [ |
| 269 | + "Bash(rm -rf*)", |
| 270 | + "Edit(/etc/*)" |
| 271 | + ] |
| 272 | + } |
| 273 | +} |
| 274 | +``` |
| 275 | +</Accordion> |
| 276 | + |
| 277 | +<Accordion title="Usage Monitoring & Alerts"> |
| 278 | +Set up monitoring in Portkey: |
| 279 | + |
| 280 | +1. **Create Alerts** |
| 281 | + - Budget threshold warnings at 80% |
| 282 | + - Unusual usage patterns |
| 283 | + - Failed request spikes |
| 284 | + |
| 285 | +2. **Regular Reviews** |
| 286 | + - Weekly cost reports by team |
| 287 | + - Model usage distribution |
| 288 | + - Performance metrics |
| 289 | + |
| 290 | +3. **Compliance Tracking** |
| 291 | + - Export logs for audit trails |
| 292 | + - Monitor for sensitive data in prompts |
| 293 | + - Track user activity patterns |
| 294 | +</Accordion> |
| 295 | +</AccordionGroup> |
| 296 | + |
| 297 | +# Advanced Features |
| 298 | + |
| 299 | +## Caching for Faster Responses |
| 300 | + |
| 301 | +Enable caching in your Portkey config to speed up repeated queries: |
| 302 | + |
| 303 | +```json |
| 304 | +{ |
| 305 | + "virtual_key": "YOUR_VIRTUAL_KEY", |
| 306 | + "cache": { |
| 307 | + "mode": "simple", |
| 308 | + } |
| 309 | +} |
| 310 | +``` |
| 311 | + |
| 312 | +## Security & Compliance |
| 313 | + |
| 314 | +<CardGroup cols={2}> |
| 315 | +<Card title="Guardrails" icon="shield-check" href="/product/guardrails"> |
| 316 | +Implement PII detection and content filtering for Claude Code interactions |
| 317 | +</Card> |
| 318 | + |
| 319 | +<Card title="Access Controls" icon="lock" href="/product/enterprise-offering/access-control-management"> |
| 320 | +Set up fine-grained permissions and audit logging |
| 321 | +</Card> |
| 322 | + |
| 323 | +<Card title="Budget Management" icon="coins" href="/product/ai-gateway/virtual-keys/budget-limits"> |
| 324 | +Prevent overspending with hard budget limits |
| 325 | +</Card> |
| 326 | + |
| 327 | +<Card title="Audit Logs" icon="clipboard-list" href="/product/enterprise-offering/access-control-management#audit-logs"> |
| 328 | +Track all Claude Code usage for compliance |
| 329 | +</Card> |
| 330 | +</CardGroup> |
| 331 | + |
| 332 | +# References |
| 333 | + |
| 334 | +- [Claude Code Proxy Documentation](https://docs.anthropic.com/en/docs/claude-code/bedrock-vertex-proxies) - Official Anthropic documentation for proxy configuration |
| 335 | +- [Portkey Virtual Keys](/product/ai-gateway/virtual-keys) - Secure credential management |
| 336 | +- [Portkey Configs](/product/ai-gateway/configs) - Advanced routing configuration |
| 337 | + |
| 338 | +# Next Steps |
| 339 | + |
| 340 | +- [Set up team workflows](/docs/product/enterprise-offering/org-management) with role-based access |
| 341 | +- [Configure advanced routing](/docs/product/ai-gateway) for reliability |
| 342 | +- [Implement guardrails](/docs/product/guardrails) for secure coding assistance |
| 343 | +- [Monitor usage patterns](/docs/product/observability) across your organization |
| 344 | + |
| 345 | +<Note> |
| 346 | +For enterprise support and custom features, contact our [enterprise team](https://portkey.sh/claude-code-enterprise). |
| 347 | +</Note> |
0 commit comments