Skip to content

fix(router): use LiteLLM master key in responses_api and default backend_conf in execute_proxy - #384

Merged
sheepdestroyer merged 4 commits into
masterfrom
fix/responses-api-auth-and-execute-proxy
Aug 5, 2026
Merged

fix(router): use LiteLLM master key in responses_api and default backend_conf in execute_proxy#384
sheepdestroyer merged 4 commits into
masterfrom
fix/responses-api-auth-and-execute-proxy

Conversation

@sheepdestroyer

@sheepdestroyersheepdestroyer commented Jul 26, 2026

Copy link
Copy Markdown
Owner

Fixes 2 issues discovered during dev endpoint verification:

  1. : Use LiteLLM master key when proxying requests to LiteLLM's endpoint instead of client auth header.
  2. : Default to LiteLLM proxy when requested model is not explicitly mapped in config dictionary (e.g. , , ).

Verified with (35/35 passed).

Summary by Sourcery

Use LiteLLM master key consistently for proxied responses and default unmapped backend models to the LiteLLM proxy.

Bug Fixes:

  • Ensure responses_api always uses the LiteLLM master key instead of client Authorization headers when proxying to LiteLLM.
  • Fallback to a default LiteLLM proxy configuration when execute_proxy is called with a model not present in the backends mapping.

Summary by CodeRabbit

  • Bug Fixes
    • Improved authorization handling for Responses API requests by consistently using the configured service credentials.
    • Added a fallback connection configuration when a requested model is not explicitly mapped, preventing unnecessary backend configuration errors.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@sourcery-ai

Copy link
Copy Markdown
Contributor

🧙 Sourcery is reviewing your pull request!


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai

coderabbitaiBot commented Jul 26, 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:51 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

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 Plus

Run ID: 9c103ad9-1168-4927-a9aa-2b14d5c1fb76

📥 Commits

Reviewing files that changed from the base of the PR and between aa84644 and 6d34d83.

📒 Files selected for processing (1)
  • router/main.py
📝 Walkthrough

Walkthrough

The proxy now always forwards the configured LiteLLM master key for /responses requests and creates a default LiteLLM backend when a requested model is missing from the configured backend mapping.

Changes

Proxy routing behavior

Layer / File(s)Summary
Responses authorization forwarding
router/main.py
The /responses proxy path always sets the upstream Authorization header from LITELLM_MASTER_KEY.
Unknown backend fallback
router/main.py
execute_proxy logs missing backends and creates a default backend using {LITELLM_URL}/v1 and the dynamic master-key placeholder.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check nameStatusExplanation
Docstring Coverage✅ PassedNo functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check✅ PassedCheck skipped because no linked issues were found for this pull request.
Out of Scope Changes check✅ PassedCheck skipped because no linked issues were found for this pull request.
Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
Title check✅ PassedThe title clearly describes the two main routing fixes in router/main.py and matches the pull request objectives.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/responses-api-auth-and-execute-proxy

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.

@coderabbitaicoderabbitaiBot 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

🧹 Nitpick comments (1)
router/main.py (1)

2127-2130: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Fail fast when LITELLM_MASTER_KEY is unavailable.

os.getenv can produce Bearer None for Responses requests, while the new fallback can resolve to the literal placeholder. Validate the key at startup, or return a clear configuration error before proxying instead of producing opaque upstream authorization failures.

Also applies to: 2826-2830

🤖 Prompt for 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.
In `@router/main.py` around lines 2127 - 2130, Validate LITELLM_MASTER_KEY before
constructing the Authorization header in the Responses request path and the
corresponding code at the additional occurrence. Fail fast with a clear
configuration error when the key is unset or resolves to a placeholder,
preventing requests from being proxied with invalid credentials; otherwise
preserve the existing Bearer header behavior.
🤖 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 `@router/main.py`:
- Around line 2127-2130: The responses_api route currently forwards the server’s
LITELLM_MASTER_KEY without authenticating callers. Update responses_api and its
/v1/responses and /responses route declarations to enforce the existing
client-auth dependency, or validate and reject requests lacking a valid
Authorization header before proxying; preserve the upstream master-key
authorization only after client authentication succeeds.
---
Nitpick comments:
In `@router/main.py`:
- Around line 2127-2130: Validate LITELLM_MASTER_KEY before constructing the
Authorization header in the Responses request path and the corresponding code at
the additional occurrence. Fail fast with a clear configuration error when the
key is unset or resolves to a placeholder, preventing requests from being
proxied with invalid credentials; otherwise preserve the existing Bearer header
behavior.
🪄 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 Plus

Run ID: 950a9688-dcfb-42ac-bf15-c33f85549f29

📥 Commits

Reviewing files that changed from the base of the PR and between a701d3e and aa84644.

📒 Files selected for processing (1)
  • router/main.py

Comment threadrouter/main.py
Comment on lines 2127 to 2130
litellm_key = os.getenv("LITELLM_MASTER_KEY")
auth_header = request.headers.get("Authorization")
if not auth_header or not auth_header.startswith("Bearer "):
auth_header = f"Bearer {litellm_key}"

headers = {
"Authorization": auth_header,
"Authorization": f"Bearer {litellm_key}",
"Content-Type": request.headers.get("content-type", "application/json"),

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.

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
rg -n -C 6 'responses_api|/responses|Depends\(|middleware|LITELLM_MASTER_KEY' router/main.py

Repository: sheepdestroyer/LLM-Routing

Length of output: 5601


🏁 Script executed:

#!/bin/bashset -euo pipefail
echo"== file size =="
wc -l router/main.py
echo"== app declaration and decorators/top-level routes within first 130 lines =="
sed -n '1,140p' router/main.py
echo"== relevant responses_api section =="
sed -n '2045,2185p' router/main.py
echo"== occurrences of dependencies/decorated handlers/routes =="
python3 - <<'PY'from pathlib import Pathp = Path("router/main.py")text = p.read_text()for i,line in enumerate(text.splitlines(),1): if "`@app`." in line or line.startswith("async def responses_api") or "Depends(" in line: start=max(1,i-8); end=min(len(text.splitlines()), i+8) print(f"\n--- around line {i} ---") for n in range(start,end+1): print(f"{n:4}: {text.splitlines()[n-1]}")PYecho"== route names/paths =="
python3 - <<'PY'from pathlib import Pathtext = Path("router/main.py").read_text()for i,line in enumerate(text.splitlines(),1): if ("`@app.api_route`" in line or "`@app.post`" in line or "`@app.get`" in line or "`@app.add_route`" in line): # show next line as route handler name/line print(f"{i}: {line.strip()}") if i < len(text.splitlines()): print(f"{i+1}: {text.splitlines()[i].strip()}")PY

Repository: sheepdestroyer/LLM-Routing

Length of output: 23590


Add client authentication before proxying Responses API requests.

responses_api(request: Request) is decorated by @app.api_route("/v1/responses") / @app.api_route("/responses") without a dependency, then forwards LITELLM_MASTER_KEY as upstream authorization. Add and enforce a client-auth dependency for these routes, or reject requests without a valid Authorization header, to avoid exposing the LiteLLM master-key quota to any reachable caller.

🤖 Prompt for 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.
In `@router/main.py` around lines 2127 - 2130, The responses_api route currently
forwards the server’s LITELLM_MASTER_KEY without authenticating callers. Update
responses_api and its /v1/responses and /responses route declarations to enforce
the existing client-auth dependency, or validate and reject requests lacking a
valid Authorization header before proxying; preserve the upstream master-key
authorization only after client authentication succeeds.

@sheepdestroyer

Copy link
Copy Markdown
OwnerAuthor

Linked to issue #407 for tracking follow-up security validation and dynamic OpenRouter model sync fixes.

@sheepdestroyer
sheepdestroyer merged commit aeaf99f into masterAug 5, 2026
8 checks passed
@sheepdestroyer
sheepdestroyer deleted the fix/responses-api-auth-and-execute-proxy branch August 5, 2026 17:46
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@sheepdestroyer