> ## Documentation Index
> Fetch the complete documentation index at: https://portkey-docs-add-third-party-integration-issues-fixes.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Claude Code

> Integrate Portkey with Claude Code for enterprise-grade AI coding assistance with observability, reliability, and governance

[Claude Code](https://code.claude.com/docs/en/overview) is one of the most popular AI coding tools for boosting developer productivity. Platform teams use Portkey to roll out Claude Code across their organization—without handing out raw API keys or losing visibility into usage.

## Why Platform Teams Use Portkey

<CardGroup cols={2}>
  <Card title="Governance & Access Control" icon="shield-check">
    No raw API keys. Create virtual keys with budget limits and rate controls. Track who's using what.
  </Card>

  <Card title="Cost Visibility" icon="chart-line">
    Claude Code can run up bills fast with agentic loops. See exactly what each team, project, or developer is spending—and set hard budget limits.
  </Card>

  <Card title="Workspace Separation" icon="building">
    Isolate teams with separate workspaces. Each gets its own budget, rate limits, and access controls. Perfect for enterprise multi-team setups.
  </Card>

  <Card title="Provider Agnostic" icon="shuffle">
    Route through Anthropic, Bedrock, or Vertex AI. Switch providers with a config change—no developer workflow changes needed.
  </Card>
</CardGroup>

**For developers:** Setup takes 2 minutes. Copy a config, paste it, start coding.

<Note>
  **Important:** Always use the latest version of Claude Code. Older versions may not work with Portkey's gateway.

  ```bash theme={null}
  claude update
  ```
</Note>

## Choose Your Provider

<CardGroup cols={3}>
  <Card title="Anthropic Direct" icon="bolt" href="/virtual_key_old/integrations/libraries/claude-code-anthropic">
    Route through Anthropic's API directly. Includes Max plan and OAuth support.
  </Card>

  <Card title="Amazon Bedrock" icon="aws" href="/virtual_key_old/integrations/libraries/claude-code-bedrock">
    Use Claude through AWS Bedrock with cross-region inference support.
  </Card>

  <Card title="Google Vertex AI" icon="google" href="/virtual_key_old/integrations/libraries/claude-code-vertex">
    Use Claude through Google Cloud's Vertex AI platform.
  </Card>
</CardGroup>

## How It Works

Portkey acts as an LLM gateway between Claude Code and your chosen provider. All requests route through Portkey, giving you:

```
Claude Code → Portkey Gateway → Anthropic / Bedrock / Vertex AI
```

## Quick Start (All Providers)

The configuration pattern is the same for all providers — only the provider name and model names change:

<CodeGroup>
  ```json Anthropic theme={null}
  {
    "env": {
      "ANTHROPIC_BASE_URL": "https://api.portkey.ai/v1",
      "ANTHROPIC_CUSTOM_HEADERS": "x-portkey-api-key: YOUR_PORTKEY_API_KEY\nx-portkey-provider: anthropic\nx-portkey-virtual-key: YOUR_VIRTUAL_KEY",
      "ANTHROPIC_MODEL": "claude-sonnet-4-20250514"
    }
  }
  ```

  ```json Bedrock theme={null}
  {
    "env": {
      "ANTHROPIC_BEDROCK_BASE_URL": "https://api.portkey.ai/v1",
      "ANTHROPIC_CUSTOM_HEADERS": "x-portkey-api-key: YOUR_PORTKEY_API_KEY\nx-portkey-provider: bedrock\nx-portkey-virtual-key: YOUR_VIRTUAL_KEY",
      "ANTHROPIC_MODEL": "us.anthropic.claude-sonnet-4-20250514-v1:0",
      "CLAUDE_CODE_SKIP_BEDROCK_AUTH": 1,
      "CLAUDE_CODE_USE_BEDROCK": 1
    }
  }
  ```

  ```json Vertex AI theme={null}
  {
    "env": {
      "ANTHROPIC_VERTEX_BASE_URL": "https://api.portkey.ai/v1",
      "ANTHROPIC_CUSTOM_HEADERS": "x-portkey-api-key: YOUR_PORTKEY_API_KEY\nx-portkey-provider: vertex-ai\nx-portkey-virtual-key: YOUR_VIRTUAL_KEY",
      "ANTHROPIC_MODEL": "claude-3-7-sonnet@20250219",
      "CLAUDE_CODE_SKIP_VERTEX_AUTH": 1,
      "CLAUDE_CODE_USE_VERTEX": 1
    }
  }
  ```
</CodeGroup>

<Warning>
  **Model names are required.** Each provider uses different model IDs. Without the correct model settings, requests will fail.
</Warning>

## Why Use Portkey with Claude Code?

### Cross-Provider Fallbacks

Never lose a coding session due to provider outages. Configure automatic failover:

```json theme={null}
{
  "strategy": { "mode": "fallback" },
  "targets": [
    { "virtual_key": "anthropic-virtual-key" },
    { "virtual_key": "bedrock-virtual-key" },
    { "virtual_key": "vertex-virtual-key" }
  ]
}
```

### Budget Controls for Agentic Coding

Claude Code can run expensive agentic loops. Set hard limits on your virtual keys:

* **Cost limits**: Maximum spend per day/week/month
* **Rate limits**: Requests per minute/hour

### Full Session Observability

Track every request in your coding session:

* Request/response logs with full context
* Token usage and cost breakdowns
* Latency metrics
* Metadata for grouping related requests

### Caching

Reduce costs and latency for repeated queries (common in iterative coding):

```json theme={null}
{
  "virtual_key": "YOUR_VIRTUAL_KEY",
  "cache": { "mode": "simple" }
}
```

## Common Configuration

### Adding Metadata

Track Claude Code usage by team, project, or user:

```json theme={null}
{
  "env": {
    "ANTHROPIC_CUSTOM_HEADERS": "x-portkey-api-key: YOUR_KEY\nx-portkey-provider: anthropic\nx-portkey-virtual-key: YOUR_VIRTUAL_KEY\nx-portkey-metadata: {\"_user\": \"john.doe\", \"team\": \"engineering\"}"
  }
}
```

## Troubleshooting

| Symptom                | Cause                         | Fix                                        |
| ---------------------- | ----------------------------- | ------------------------------------------ |
| Requests not appearing | Old Claude Code version       | Run `claude update`                        |
| Authentication errors  | Wrong virtual key             | Verify virtual key ID in Portkey dashboard |
| Model not found        | Wrong model name for provider | Check provider-specific model IDs          |

See provider-specific pages for detailed troubleshooting.

## Next Steps

<CardGroup cols={2}>
  <Card title="Portkey Configs" icon="gear" href="/virtual_key_old/product/ai-gateway/configs">
    Learn about fallbacks, load balancing, and routing strategies
  </Card>

  <Card title="Budget & Limits" icon="dollar-sign" href="/virtual_key_old/product/ai-gateway/virtual-keys/budget-limits">
    Set up spending controls for your team
  </Card>

  <Card title="Observability" icon="chart-line" href="/virtual_key_old/product/observability">
    Deep dive into logs, traces, and analytics
  </Card>

  <Card title="Virtual Keys" icon="key" href="/virtual_key_old/product/ai-gateway/virtual-keys">
    Manage provider credentials securely
  </Card>
</CardGroup>
