Skip to content

fix: add OPENROUTER_API_KEY to LiteLLM container env#287

Closed
sheepdestroyer wants to merge 3 commits into
masterfrom
pr-285
Closed

fix: add OPENROUTER_API_KEY to LiteLLM container env#287
sheepdestroyer wants to merge 3 commits into
masterfrom
pr-285

Conversation

@sheepdestroyer

@sheepdestroyer sheepdestroyer commented Jul 12, 2026

Copy link
Copy Markdown
Owner

Problem

The LiteLLM gateway container was missing OPENROUTER_API_KEY in its environment. This caused all OpenRouter free model requests to fail with Missing Authentication header (401), which cascaded through the fallback chain and eventually produced 429 errors for the llm-routing-auto-free routing model.

Root Cause

pod.yaml defined OLLAMA_API_KEY and other secrets for the LiteLLM container, but OPENROUTER_API_KEY was never added. Since start-stack.sh requires the key and uses it for the router (via .env sourcing), the value already exists in .env — it just wasn't being rendered into the LiteLLM container's environment.

Fix

  • Added OPENROUTER_API_KEY_PLACEHOLDER to pod.yaml LiteLLM container env block
  • Added OPENROUTER_API_KEY to the export list in render_pod_yaml()
  • Added the placeholder to the validation list and replacement logic in start-stack.sh

Verification

  • All 101 tests pass
  • 24/24 canonical endpoint verification passes in dev
  • Direct llm-routing-auto-free chat completion test succeeds (was 429 before fix)

Summary by CodeRabbit

  • New Features
    • Added OpenRouter API key configuration to the LiteLLM Gateway.
    • Stack startup now populates the API key automatically when generating the pod configuration.

The LiteLLM gateway container was missing OPENROUTER_API_KEY in its
environment, causing all OpenRouter free model requests to fail with
'Missing Authentication header' (401). This cascaded through the
fallback chain and eventually produced 429 errors for the
llm-routing-auto-free routing model.

Added OPENROUTER_API_KEY_PLACEHOLDER to pod.yaml LiteLLM container env
and the corresponding placeholder rendering in start-stack.sh.

Verified: 24/24 canonical endpoints pass in dev environment.
Tested: llm-routing-auto-free chat completion succeeds (not 429).

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @sheepdestroyer, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@coderabbitai

coderabbitai Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@sheepdestroyer, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 32 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 25d46492-0a5d-4d5c-a04d-b4dc009e0ee6

📥 Commits

Reviewing files that changed from the base of the PR and between d12f214 and 32fc19f.

📒 Files selected for processing (2)
  • litellm/config.yaml
  • start-stack.sh
📝 Walkthrough

Walkthrough

The LiteLLM Gateway pod now declares an OpenRouter API key placeholder. start-stack.sh exports the key, validates the placeholder, and replaces it while rendering pod.yaml.

Changes

OpenRouter API key configuration

Layer / File(s) Summary
OpenRouter key template rendering
pod.yaml, start-stack.sh
The LiteLLM Gateway receives OPENROUTER_API_KEY; render_pod_yaml exports the value, validates OPENROUTER_API_KEY_PLACEHOLDER, and performs the replacement.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Possibly related PRs

  • sheepdestroyer/LLM-Routing#184: Modifies the same pod environment and render_pod_yaml placeholder-replacement paths for router API key configuration.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately summarizes the main change: adding OPENROUTER_API_KEY to the LiteLLM container environment.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch pr-285

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds support for the OPENROUTER_API_KEY environment variable across pod.yaml and start-stack.sh. The feedback suggests refactoring the extremely long export statement in start-stack.sh into multiple lines to improve readability and prevent merge conflicts.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread start-stack.sh Outdated

render_pod_yaml() {
export WORKDIR HOME LITELLM_MASTER_KEY UI_USERNAME UI_PASSWORD POSTGRES_PASSWORD NEXTAUTH_SECRET SALT ENCRYPTION_KEY LANGFUSE_INIT_USER_PASSWORD MINIO_ROOT_USER MINIO_ROOT_PASSWORD OLLAMA_API_KEY LANGFUSE_PUBLIC_KEY LANGFUSE_SECRET_KEY CLASSIFIER_INPUT_MAX_CHARS REDIS_AUTH CLICKHOUSE_PASSWORD PUBLIC_BASE_URL ROUTING_DOMAIN POD_NAME DATA_ROOT ROUTER_IMAGE ROUTER_PORT LITELLM_PORT LANGFUSE_WEB_PORT LANGFUSE_WORKER_PORT POSTGRES_PORT VALKEY_CACHE_PORT VALKEY_LF_PORT CLICKHOUSE_HTTP_PORT CLICKHOUSE_TCP_PORT CLICKHOUSE_INTERSERVER_PORT MINIO_S3_PORT MINIO_CONSOLE_PORT
export WORKDIR HOME LITELLM_MASTER_KEY UI_USERNAME UI_PASSWORD POSTGRES_PASSWORD NEXTAUTH_SECRET SALT ENCRYPTION_KEY LANGFUSE_INIT_USER_PASSWORD MINIO_ROOT_USER MINIO_ROOT_PASSWORD OLLAMA_API_KEY OPENROUTER_API_KEY LANGFUSE_PUBLIC_KEY LANGFUSE_SECRET_KEY CLASSIFIER_INPUT_MAX_CHARS REDIS_AUTH CLICKHOUSE_PASSWORD PUBLIC_BASE_URL ROUTING_DOMAIN POD_NAME DATA_ROOT ROUTER_IMAGE ROUTER_PORT LITELLM_PORT LANGFUSE_WEB_PORT LANGFUSE_WORKER_PORT POSTGRES_PORT VALKEY_CACHE_PORT VALKEY_LF_PORT CLICKHOUSE_HTTP_PORT CLICKHOUSE_TCP_PORT CLICKHOUSE_INTERSERVER_PORT MINIO_S3_PORT MINIO_CONSOLE_PORT

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The export statement has grown extremely long (over 500 characters), making it difficult to read, maintain, and prone to merge conflicts. Consider splitting it into multiple lines using backslashes to improve readability and maintainability.

    export \
        WORKDIR \
        HOME \
        LITELLM_MASTER_KEY \
        UI_USERNAME \
        UI_PASSWORD \
        POSTGRES_PASSWORD \
        NEXTAUTH_SECRET \
        SALT \
        ENCRYPTION_KEY \
        LANGFUSE_INIT_USER_PASSWORD \
        MINIO_ROOT_USER \
        MINIO_ROOT_PASSWORD \
        OLLAMA_API_KEY \
        OPENROUTER_API_KEY \
        LANGFUSE_PUBLIC_KEY \
        LANGFUSE_SECRET_KEY \
        CLASSIFIER_INPUT_MAX_CHARS \
        REDIS_AUTH \
        CLICKHOUSE_PASSWORD \
        PUBLIC_BASE_URL \
        ROUTING_DOMAIN \
        POD_NAME \
        DATA_ROOT \
        ROUTER_IMAGE \
        ROUTER_PORT \
        LITELLM_PORT \
        LANGFUSE_WEB_PORT \
        LANGFUSE_WORKER_PORT \
        POSTGRES_PORT \
        VALKEY_CACHE_PORT \
        VALKEY_LF_PORT \
        CLICKHOUSE_HTTP_PORT \
        CLICKHOUSE_TCP_PORT \
        CLICKHOUSE_INTERSERVER_PORT \
        MINIO_S3_PORT \
        MINIO_CONSOLE_PORT

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@start-stack.sh`:
- Line 616: Validate that OPENROUTER_API_KEY is non-empty before the export and
rendering flow in start-stack.sh, failing immediately with a clear error when it
is blank. Preserve the existing export behavior for valid values and apply the
same validation at the corresponding second occurrence.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4fc2ffd2-1525-4218-92ea-bd658b43a08a

📥 Commits

Reviewing files that changed from the base of the PR and between 72d9a83 and d12f214.

📒 Files selected for processing (2)
  • pod.yaml
  • start-stack.sh

Comment thread start-stack.sh Outdated
boy added 2 commits July 13, 2026 01:00
The 5 static entries (agent-simple-core through agent-advanced-core)
were safety nets that defined hardcoded OpenRouter :free models,
including 3 Google models (gemma-4-31b, gemma-4-26b) that frequently
hit quota limits.

The dynamic roster sync (router/main.py) already registers 31+ AA-scored
free models at startup via LiteLLM's /model/new API. This is the sole
source of truth for agent tier deployments now. Removing the static
entries eliminates Google models that were polluting the routing pool
alongside the dynamic roster.

Also applies the OPENROUTER_API_KEY fix from the same branch.

Tested: 101/101 pytest, 23/24 canonical endpoints (1 timeout is
pre-existing — free model rate limits)
Per Gemini Code Assist review: the 500+ character export statement
was hard to read and prone to merge conflicts. Split into one var
per line with backslash continuations.

CodeRabbit's suggestion to add OPENROUTER_API_KEY non-empty check
is already handled at lines 127-152 — the script exits before
reaching this function if the key is empty.
@sheepdestroyer

Copy link
Copy Markdown
Owner Author

Closing in favor of a fresh PR with all review fixes applied and consolidated commits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant