Skip to content

feat(openrouter): Add provider selection and prioritization support#1373

Merged
joshua-mo-143 merged 9 commits into0xPlaygrounds:mainfrom
milutinke:main
Feb 16, 2026
Merged

feat(openrouter): Add provider selection and prioritization support#1373
joshua-mo-143 merged 9 commits into0xPlaygrounds:mainfrom
milutinke:main

Conversation

@milutinke
Copy link
Contributor

@milutinke milutinke commented Feb 7, 2026

Add OpenRouter Provider Selection and Prioritization

Description

Implements OpenRouter's Provider Routing API, enabling fine-grained control over which providers handle requests.

Motivation: I personally, and many others (probably) need a more fine-grained control over what model providers we want to use. For an example, my personal use case is only using providers with Zero Data Retention policy and FP8, while sorting for throughput.

Provider Selection Controls:

  • order - Provider priority ordering
  • only - Hard allowlist
  • ignore - Blocklist
  • allow_fallbacks - Fail-closed behavior control

Compatibility & Policy Filters:

  • require_parameters - Strict parameter support
  • data_collection - Allow/deny data collection
  • zdr - Zero Data Retention endpoints only

Performance & Cost Preferences:

  • sort - By price/throughput/latency (supports complex partition config for multi-model)
  • preferred_min_throughput / preferred_max_latency - Simple or percentile thresholds
  • max_price - Hard price ceiling (prompt/completion/request/image)

Quantization Filter:

  • quantizations - Filter by int4/int8/fp8/fp16/bf16/fp32
let prefs = ProviderPreferences::new()
    .order(["DeepInfra", "DeepSeek"])
    .sort(ProviderSortStrategy::Throughput)
    .quantizations([Quantization::Fp8]);

let agent = client
    .agent("deepseek/deepseek-v3.2")
    .additional_params(prefs.to_json())
    .build();

Examples in: rig/rig-core/examples/openrouter_provider_selection.rs

Type of change

  • New feature

Testing

  • 38 unit tests covering serialization, deserialization, builder patterns, defaults, and edge cases
  • Example file (openrouter_provider_selection.rs) demonstrating all features with deepseek/deepseek-v3.2
  • Manually run the ‎rig/rig-core/examples/openrouter_provider_selection.rs
image

Copilot AI and others added 6 commits February 7, 2026 10:06
Co-authored-by: milutinke <441903+milutinke@users.noreply.github.com>
…Router docs

- Rename `allow` to `only` (hard allowlist per API spec)
- Add `allow_fallbacks: boolean` for controlling fallback behavior
- Add `require_parameters: boolean` for strict parameter support
- Move `data_collection` from nested `require` to top-level
- Add `zdr: boolean` for Zero Data Retention
- Remove `Quality` from ProviderSort (not in spec)
- Move `quantizations` from nested `require` to top-level
- Add `preferred_min_throughput` with percentile support
- Add `preferred_max_latency` with percentile support
- Add `max_price` struct for hard price ceilings
- Support complex `sort` object with `by` and `partition`
- Remove `ProviderRequire` struct (fields should be top-level)
- Update tests to match new API (24 tests passing)
- Update example to match official documentation examples

Co-authored-by: milutinke <441903+milutinke@users.noreply.github.com>
…sary comments

- Add 14 new edge case tests for better coverage
- Test DataCollection::default(), Quantization::Unknown, SortPartition variants
- Test PercentileThresholds::default() and all four percentile fields
- Test LatencyThreshold variants (Simple and Percentile)
- Test MaxPrice with all fields and default values
- Test ProviderPreferences::default() for all None fields
- Test ProviderSort::from implementations
- Test ProviderSortConfig without partition
- Test deserialization of complex sort object
- Test preferred_max_latency serialization
- Test empty arrays for order and quantizations
- Remove "// Example N from docs:" comments from tests
- Remove section divider from test module
- Clean up example file comments

Co-authored-by: milutinke <441903+milutinke@users.noreply.github.com>
…pseek-v3.2

Update example to use deepseek/deepseek-v3.2 model with its actual providers:
- DeepInfra, DeepSeek, Chutes, AtlasCloud for provider ordering
- Google Vertex for blocklist example
- Fp8 quantization (most providers use fp8)
- Realistic price ceiling ($0.30/$0.50) matching provider prices
- Throughput threshold (15 tps) matching DeepSeek providers

Co-authored-by: milutinke <441903+milutinke@users.noreply.github.com>
…cture

feat(openrouter): Add provider selection and prioritization support
@joshua-mo-143
Copy link
Collaborator

Looks OK to me. Needs cargo fmt to pass ci

@joshua-mo-143 joshua-mo-143 added the awaiting changes This PR is awaiting some changes from the original PR submitter. label Feb 8, 2026
Copilot AI and others added 3 commits February 11, 2026 23:57
Co-authored-by: milutinke <441903+milutinke@users.noreply.github.com>
Fix cargo fmt formatting issues in openrouter provider files
@milutinke
Copy link
Contributor Author

@joshua-mo-143 Hello, I've fixed the issue, the checks pass now.

@milutinke
Copy link
Contributor Author

Can we get this merged?

@joshua-mo-143
Copy link
Collaborator

Can we get this merged?

Hey, apologies for late response. I'll be merging today as it'll be release day today so anything that is ready-ish to be merged will be merged in 😄

@joshua-mo-143 joshua-mo-143 added ready to merge PR is ready to merge. and removed awaiting changes This PR is awaiting some changes from the original PR submitter. labels Feb 16, 2026
@joshua-mo-143 joshua-mo-143 added this pull request to the merge queue Feb 16, 2026
Merged via the queue into 0xPlaygrounds:main with commit d7ad747 Feb 16, 2026
5 checks passed
@github-actions github-actions bot mentioned this pull request Feb 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready to merge PR is ready to merge.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants