Skip to content

Repository files navigation

coding-agent-litellm-config

Auto-generated OpenCode and Claude Code configuration for our LiteLLM proxy.

Problem

When using OpenCode with a LiteLLM proxy via @ai-sdk/openai-compatible, OpenCode cannot look up model capabilities (vision, PDF support, reasoning, costs, context limits) from models.dev because the model names are custom aliases that don't match any known provider/model entries.

This means features like image input silently fail — OpenCode strips the image before it ever reaches the proxy.

Claude Code also needs configuration to route through LiteLLM's Bedrock pass-through endpoint, with the correct model names pinned.

Solution

The generate.py script:

  1. Reads the LiteLLM config.yml to get model aliases and their underlying provider models
  2. Fetches the full model metadata from models.dev
  3. Maps litellm provider prefixes (azure/, bedrock/, vertex_ai/) to models.dev providers
  4. Generates an opencode.json with full metadata (modalities, costs, limits, capabilities)
  5. Generates a claude-settings.json for Claude Code with Bedrock pass-through configuration

Usage

OpenCode

Copy or symlink opencode.json to your global opencode config:

cp opencode.json ~/.config/opencode/opencode.json

Or symlink it:

ln -sf $(pwd)/opencode.json ~/.config/opencode/opencode.json

Claude Code

The generated claude-settings.json configures Claude Code to use LiteLLM's Bedrock pass-through. It auto-detects the latest opus, sonnet, and haiku models from the LiteLLM config.

Install (works before or after installing Claude Code)

git clone git@github.com:i-dot-ai/coding-agent-litellm-config.git
cd coding-agent-litellm-config
./install.sh

The install script will:

  1. Deep-merge claude-settings.json into ~/.claude/settings.json (creating it if it doesn't exist, preserving your existing hooks, plugins, and extra env vars if it does)
  2. Prompt for your LiteLLM API key (ANTHROPIC_AUTH_TOKEN) and save it to settings — you can also skip and add it later
  3. Register a SessionStart hook so Claude Code auto-pulls updates when a new session starts (throttled to once per hour, runs in background)

The install works from any branch — if claude-settings.json doesn't exist locally, it reads it from origin/main.

The API key is per-user and not included in the generated config, but the merge preserves it across updates.

Now install and run Claude Code:

npm install -g @anthropic-ai/claude-code
claude

Rollback and pause

A backup of your settings is saved before each auto-update to ~/.config/coding-agent-litellm-config/settings.json.backup.

To restore and pause auto-updates:

cp ~/.config/coding-agent-litellm-config/settings.json.backup ~/.claude/settings.json
touch ~/.config/coding-agent-litellm-config/paused

To resume auto-updates:

rm ~/.config/coding-agent-litellm-config/paused

Uninstall

./uninstall.sh

Removes the auto-update hook. Your other settings (hooks, plugins, env vars) are preserved.

What the generated settings contain

{
  "model": "bedrock-claude-4.6-opus",
  "env": {
    "ANTHROPIC_BEDROCK_BASE_URL": "https://llm-gateway.i.ai.gov.uk/bedrock",
    "CLAUDE_CODE_USE_BEDROCK": "1",
    "CLAUDE_CODE_SKIP_BEDROCK_AUTH": "1",
    "ANTHROPIC_DEFAULT_OPUS_MODEL": "bedrock-claude-4.6-opus",
    "ANTHROPIC_DEFAULT_SONNET_MODEL": "bedrock-claude-4.6-sonnet",
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "bedrock-claude-4.5-haiku"
  }
}
  • CLAUDE_CODE_USE_BEDROCK tells Claude Code to use the Bedrock API format
  • CLAUDE_CODE_SKIP_BEDROCK_AUTH skips local AWS auth since LiteLLM handles authentication with AWS
  • ANTHROPIC_BEDROCK_BASE_URL points to LiteLLM's Bedrock pass-through endpoint
  • ANTHROPIC_DEFAULT_*_MODEL pins Claude Code to specific model aliases from the LiteLLM config

The model names are auto-detected from the LiteLLM config by finding bedrock Claude models and picking the latest version of each tier (opus, sonnet, haiku).

Regenerate manually

pip install -r requirements.txt

python generate.py \
  --litellm-config /path/to/core-llm-gateway/backend/config/config.yml \
  --base-url "https://llm-gateway.i.ai.gov.uk/v1" \
  --output opencode.json \
  --claude-output claude-settings.json

Automatic updates

Server-side: A GitHub Action runs daily and whenever the litellm config changes, regenerating both opencode.json and claude-settings.json and committing any updates.

Client-side: If you ran ./install.sh, Claude Code will fetch origin/main on new session start (background, throttled to once/hour) and merge any changes into ~/.claude/settings.json. This works regardless of which branch is checked out locally.

To trigger from core-llm-gateway when the config changes, add a dispatch step to the gateway's CI:

- name: Trigger opencode config update
  if: contains(github.event.commits.*.modified, 'backend/config/config.yml')
  uses: peter-evans/repository-dispatch@v3
  with:
    token: ${{ secrets.GH_PAT }}
    repository: i-dot-ai/coding-agent-litellm-config
    event-type: litellm-config-updated

Provider mapping

LiteLLM prefix models.dev provider
azure/ azure
bedrock/ amazon-bedrock
vertex_ai/ google-vertex
openai/ openai
anthropic/ anthropic
gemini/ google
mistral/ mistral

What gets mapped

For each model, the script copies from models.dev:

  • modalities (input: text/image/pdf/audio/video, output: text)
  • limit (context window, max output tokens)
  • cost (input/output per million tokens, cache read/write)
  • reasoning, temperature, tool_call, attachment capability flags

About

Auto-generated OpenCode config for LiteLLM proxy - maps model capabilities from models.dev

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages