Add config.yaml custom model routing with quota-aware provider selection#3394
Merged
Add config.yaml custom model routing with quota-aware provider selection#3394
Conversation
Co-authored-by: hlohaus <983577+hlohaus@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add config.yaml support for custom model routing
Add config.yaml custom model routing with quota-aware provider selection
Mar 19, 2026
Collaborator
|
@copilot quota.balance is only for pollinations. All providers have his own qouta stats format |
Co-authored-by: hlohaus <983577+hlohaus@users.noreply.github.com>
Contributor
Author
Fixed in 8fd8cd5.
Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds LiteLLM-style
config.yamlsupport for defining named model routes that fan out to real providers with optional quota/error-count conditions, quota caching, and 429-triggered cache invalidation.Core module:
g4f/providers/config_provider.pyQuotaCache– TTL-based cache (5 min) forget_quota()results per provider; immediately invalidated on 429 responsesErrorCounter– Rolling 1-hour window error counter per providerevaluate_condition()– Safe recursive-descent parser supporting provider-specific quota fields via dot-notation (e.g.quota.balance > 0,quota.credits.remaining > 0 or error_count < 3); noevalRouterConfig– Parses and holds routes fromconfig.yamlConfigModelProvider–AsyncGeneratorProviderthat iterates configured providers, evaluates conditions, records errors, and invalidates quota cache on 429Integration
g4f/cookies.py–read_cookie_files()now loadsconfig.yamlfrom the cookies directory alongside.har/.jsonfilesg4f/client/service.py–get_model_and_provider()checksRouterConfigbefore standard model resolution, making custom names transparent to callersCondition variables
Each provider returns its own quota format from
get_quota(). Conditions support:quotaget_quota()— access any field with dot-notationquota.balance{"balance": float}quota.credits.remaining{"credits": {"remaining": int, "total": int}}balancequota.balance(PollinationsAI backward compat)error_countMissing quota keys resolve to
0.0.Config format
Place
config.yamlin your cookies dir (~/.config/g4f/cookies/or./har_and_cookies/):Requires
pyyaml(already inrequirements.txt); gracefully skipped with a log warning if absent.See
docs/config-yaml-routing.mdfor full condition syntax reference and Python API.Original prompt
💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.