Upstream exhaustion failover: route depleted sub-provider proxies through OpenRouter #88
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
nsaspy/llm-log#88
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Parent: #94
Related: #59 #61 #65 #67
Cross-repo economics: starintel-labs/starintel-biz#110
Goal
Add a first-class upstream exhaustion fallback policy to llm-log.
When a configured direct/sub-provider upstream cannot accept more work because its quota, credits, rate window, or configured capacity is exhausted, llm-log may transparently retry the same logical inference through the configured OpenRouter upstream.
This must be implemented as a generic routing-policy primitive with OpenRouter as the initial fallback target, not as ad-hoc special-case retry code.
Core routing path
What counts as "ran out"
Use the typed error classifier rather than raw status codes alone.
Default fallback-eligible classes:
Typical HTTP evidence may include 402 or 429. A 403 only counts when a provider adapter/classifier proves it means quota/capacity exhaustion.
Do not treat generic authentication, permission, policy, malformed-request, context-length, or safety/moderation errors as "ran out".
5xx/network failure may be enabled by separate policy, but is not part of the default exhaustion trigger.
Never replay after downstream commit
Fallback is only legal while llm-log still owns the full response decision and has not committed response bytes to the downstream client.
For streaming/SSE/WebSocket requests:
This avoids duplicate/divergent completions, tool-call duplication, and hidden double spend.
Credential boundary
Current transparent proxy behavior forwards the caller's provider credential. OpenRouter fallback requires a separate server-side credential.
Requirements:
Authorization/ provider-specific credential headers;This should share the server-owned provider credential mechanism in #94.
Model mapping
Direct-provider model IDs are not assumed to equal OpenRouter model IDs.
Add an explicit mapping layer:
No fuzzy model-name guessing in the live path.
Example configuration shape (exact syntax may evolve):
Secrets are referenced indirectly through the provider credential registry, not embedded here.
OpenRouter provider routing
Use OpenRouter's routing layer after llm-log crosses the fallback boundary.
OpenRouter currently supports provider-level failover for the same model by default and exposes provider routing controls such as
order,only,ignore,allow_fallbacks,quantizations,data_collection,zdr, andmax_price.llm-log should preserve configured policy constraints when constructing the fallback request.
Important: if llm-log's quantization policy disallows unknown/low-precision endpoints, the fallback must carry the allowed quantization constraint rather than broadening quality policy merely to obtain a response.
Request transformation
Implement fallback through provider adapters, not byte-blind URL substitution.
At minimum support:
If the original provider-native request cannot be represented losslessly enough for the configured fallback adapter, fail explicitly instead of silently changing semantics.
Exhaustion circuit breaker
Once a sub-provider is proven exhausted:
The state must be observable and event sourced where durable state is enabled.
Attempt chain / provenance
Record every logical request as one request/run with ordered upstream attempts.
For each attempt record:
Conceptual projection:
Cost / Biz integration
Fallback is not "free retry".
Emit normalized usage/cost events so StarIntel Biz can distinguish:
Feed the generic provider pricebook/metering contract in starintel-labs/starintel-biz#110.
A fallback may be blocked when the caller/company budget cannot reserve the expected OpenRouter cost.
Loop prevention
Observability
Expose at least:
Do not leak operator credentials or sensitive routing config.
Tests
Required fixtures:
Acceptance