mike / Claude Code 3Party Config

Last active 1 month ago

Like 0
claudecode3p.md Raw

Claude Desktop 3P Mode with LiteLLM

Claude Desktop has a third-party inference (3P) mode that allows the Desktop application to route inference requests through a custom gateway such as LiteLLM. This is configured separately from the normal Anthropic account login. Recent Claude Desktop configurations use a Claude-3p configuration directory and an inferenceProvider: "gateway" configuration. (Gist)

Important: When configuring the LiteLLM gateway URL in Claude Desktop 3P mode, do not include /v1 in the Base URL. Claude Desktop adds the /v1/... API paths itself. For example, use http://localhost:4000, not http://localhost:4000/v1. A working 3P gateway will ultimately receive requests such as /v1/models and /v1/messages. (GitHub)

1. Enable Developer Mode

Open Claude Desktop and go to:

Help → Troubleshooting → Enable Developer Mode

After enabling Developer Mode, Claude Desktop exposes the developer configuration options, including:

Developer → Configure third-party inference

This is the preferred way to create the 3P configuration.

2. Configure the LiteLLM gateway

In Configure third-party inference, select the gateway/custom provider option.

Use your LiteLLM proxy as the gateway.

For a local LiteLLM installation:

Gateway/Base URL:
http://localhost:4000

API Key:
sk-your-litellm-key

For a remote LiteLLM installation:

Gateway/Base URL:
https://litellm.example.com

API Key:
sk-your-litellm-key

Do NOT use this

http://localhost:4000/v1

Use this instead

http://localhost:4000

LiteLLM itself exposes the Anthropic-compatible API under paths such as:

/v1/messages
/v1/models

Claude Desktop's gateway configuration supplies those API paths. (GitHub)

3. LiteLLM configuration

For example, a minimal LiteLLM configuration could look like:

model_list:
  - model_name: claude-sonnet
    litellm_params:
      model: anthropic/claude-sonnet-4-6
      api_key: os.environ/ANTHROPIC_API_KEY

general_settings:
  master_key: os.environ/LITELLM_MASTER_KEY

Start LiteLLM on port 4000:

litellm --config config.yaml --port 4000

Then Claude Desktop should connect to:

http://localhost:4000

while LiteLLM handles:

http://localhost:4000/v1/messages
http://localhost:4000/v1/models

4. What the resulting 3P configuration looks like

Claude Desktop stores its 3P configuration separately from the normal Desktop configuration. On macOS, for example, configurations can be found under:

~/Library/Application Support/Claude-3p/

A representative configuration contains:

{
  "deploymentMode": "3p",
  "enterpriseConfig": {
    "inferenceProvider": "gateway",
    "inferenceGatewayBaseUrl": "http://localhost:4000",
    "inferenceGatewayApiKey": "sk-your-litellm-key",
    "inferenceGatewayAuthScheme": "bearer",
    "inferenceModels": [
      "claude-sonnet-4-6"
    ]
  }
}

The exact configuration structure can vary between Claude Desktop releases, so it is preferable to let Configure third-party inference generate the configuration rather than manually replacing the entire file. Current examples confirm the deploymentMode: "3p" and inferenceProvider: "gateway" structure. (Gist)

5. Restart Claude Desktop

After saving the third-party inference configuration, allow Claude Desktop to restart.

You should now be running in 3P mode, with inference routed approximately as follows:

┌──────────────────────┐
│    Claude Desktop    │
│                      │
│       3P Mode        │
└──────────┬───────────┘
           │
           │ Base URL:
           │ http://localhost:4000
           ▼
┌──────────────────────┐
│       LiteLLM        │
│                      │
│     /v1/messages     │
│      /v1/models      │
└──────────┬───────────┘
           │
           ▼
┌──────────────────────┐
│   Configured model   │
│                      │
│ Anthropic / OpenAI / │
│ Bedrock / etc.       │
└──────────────────────┘

6. Verify LiteLLM independently

Before troubleshooting Claude Desktop, verify that LiteLLM is responding.

For example:

curl http://localhost:4000/v1/models \
  -H "Authorization: Bearer sk-your-litellm-key"

You should get a model list.

You can also test the Anthropic Messages endpoint directly:

curl http://localhost:4000/v1/messages \
  -H "x-api-key: sk-your-litellm-key" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{
    "model": "claude-sonnet",
    "max_tokens": 100,
    "messages": [
      {
        "role": "user",
        "content": "Say hello"
      }
    ]
  }'

If these work but Claude Desktop doesn't, the problem is likely the 3P configuration rather than LiteLLM.

7. Authentication caveat

There is an important distinction between authenticating to LiteLLM and authenticating LiteLLM to Anthropic.

Your Claude Desktop 3P API key:

sk-your-litellm-key

authenticates Claude Desktop → LiteLLM.

If LiteLLM is routing to Anthropic, LiteLLM still needs valid credentials for LiteLLM → Anthropic. Current testing indicates that Claude Desktop's 3P/Cowork path does not necessarily forward an existing Claude subscription OAuth credential to LiteLLM, so a normal Anthropic API key may be required on the LiteLLM side. (GitHub)

For example:

model_list:
  - model_name: claude-sonnet
    litellm_params:
      model: anthropic/claude-sonnet-4-6
      api_key: os.environ/ANTHROPIC_API_KEY

This is different from the Claude Code CLI, which has a different credential-forwarding behavior. (GitHub)

Quick reference

Setting Value
Mode 3p
Provider gateway
LiteLLM local URL http://localhost:4000
Include /v1? No
API key Your LiteLLM virtual/master key
LiteLLM API paths /v1/messages, /v1/models
LiteLLM → Anthropic Requires appropriate Anthropic credentials
Developer Mode Help → Troubleshooting → Enable Developer Mode
Configuration Developer → Configure third-party inference

The key gotcha: Claude Desktop 3P Base URL = the gateway root, not the API version path. So if LiteLLM is listening on port 4000, enter http://localhost:4000, not http://localhost:4000/v1. (GitHub)