Skip to content

feat(flare-proxy): env-var model routing (MODEL/MODEL_OPUS/SONNET/HAIKU) - #264

Merged
getappz merged 5 commits into
masterfrom
feat/env-var-model-routing
Jul 19, 2026
Merged

getappz merged 5 commits into
masterfrom
feat/env-var-model-routing

Conversation

@getappz

@getappz getappz commented Jul 19, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • ProviderConfig::from_env() reads MODEL/MODEL_OPUS/MODEL_SONNET/MODEL_HAIKU (format provider_type/model_name), replacing the hardcoded 3-route default_free() default
  • resolve_model() substring-matches opus/sonnet/haiku against env overrides, falls back to the default MODEL route, then exact match — fixes the fix(mcp): return text asset content as UTF-8, not base64 #211 upstream_model bug (route.upstream_model is now substituted into the translated request)
  • Dropped dead route_for() (superseded by resolve_model(), zero remaining callers)
  • Added unit tests for parse_model_string and resolve_model's substring-match + fallback behavior (previously untested)

Part of #212 (flare-proxy feature parity epic), Phase 1 item #1.

Test plan

  • cargo build --workspace --all-features
  • cargo fmt --all -- --check
  • cargo test -p flare-proxy (20/20 pass)

Summary by CodeRabbit

  • New Features
    • Added environment-driven provider/model configuration via MODEL, MODEL_OPUS, MODEL_SONNET, and MODEL_HAIKU.
    • Introduced keyword-based model routing (Opus/Sonnet/Haiku) when the requested model matches supported keywords.
  • Bug Fixes
    • Improved upstream model selection to use the resolved upstream routing/model during proxying.
    • Strengthened fallback behavior for missing overrides and unsupported provider prefixes, preventing unexpected routing outcomes.

@coderabbitai

coderabbitai Bot commented Jul 19, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 57f8187b-2cce-4573-9f8a-f674dca765b7

📥 Commits

Reviewing files that changed from the base of the PR and between 48d60dc and 035dc3b.

📒 Files selected for processing (1)
  • crates/flare-proxy/src/forward.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/flare-proxy/src/forward.rs

📝 Walkthrough

Walkthrough

Provider configuration now loads model routes from environment variables, resolves keyword-specific or fallback routes, and applies each route’s upstream model to forwarded OpenAI requests.

Changes

Model routing and proxy forwarding

Layer / File(s) Summary
Provider configuration and route resolution
crates/flare-proxy/src/providers.rs
ProviderConfig adds model override fields, parses environment values, builds keyword routes, resolves fallback routes, removes route_for, and tests the routing behavior.
Proxy configuration and upstream model forwarding
crates/flare-proxy/src/lib.rs, crates/flare-proxy/src/forward.rs
The router loads environment-derived configuration, while proxy_request resolves routes and writes route.upstream_model into the outgoing request.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant proxy_request
  participant ProviderConfig
  participant Upstream
  Client->>proxy_request: Send Anthropic model request
  proxy_request->>ProviderConfig: resolve_model(model)
  ProviderConfig-->>proxy_request: Return ModelRoute
  proxy_request->>Upstream: Send translated request with route.upstream_model
  Upstream-->>proxy_request: Return response
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 36.36% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: environment-variable-based model routing in flare-proxy.
Description check ✅ Passed The description is mostly complete: Summary and Test plan are filled, and the missing Notes section is non-critical.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/env-var-model-routing

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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 `@crates/flare-proxy/src/providers.rs`:
- Around line 72-141: The provider parsing in ProviderConfig::from_env()
silently skips unsupported prefixes while retaining routes that reference them.
Validate each parsed provider prefix against the supported match arms before
building providers, and fail startup or emit a warning with clear context for
unsupported values; ensure unsupported provider_ids do not remain as apparently
valid routes that later fail with unknown provider.
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 635cdec3-843d-42b5-a079-15f21e08e448

📥 Commits

Reviewing files that changed from the base of the PR and between d9cdcdd and 15857c9.

📒 Files selected for processing (3)
  • crates/flare-proxy/src/forward.rs
  • crates/flare-proxy/src/lib.rs
  • crates/flare-proxy/src/providers.rs

Comment thread crates/flare-proxy/src/providers.rs
getappz added 3 commits July 19, 2026 20:51
An unrecognized provider prefix in MODEL/MODEL_OPUS/MODEL_SONNET/MODEL_HAIKU
was silently dropped from the providers list (the `_ => continue` arm)
while the ModelRoute referencing it survived unchanged -- so a typo'd
provider looked like a successful startup and only surfaced as an opaque
"unknown provider" error once a request actually routed to it. Validate
all parsed provider prefixes up front and fall back to default_free()
with a clear stderr message when one is unsupported.
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