Skip to content

Smart provider selection: choose pool and model by live quota, time-of-day price and job kind #186

Open

Description

@n0rpan

Want (owner 2026-11-20)

oxa chooses which provider and model to use, and when, from live facts instead of a fixed model. Today the OpenCode Go weekly quota ran out (429, retry after about 57 h) and lead stalled while the ChatGPT plan and the Alibaba Token Plan still had room.

Inputs (live where possible, owner config otherwise)

  • Quota state per pool: remaining weekly/5-hour windows from provider usage endpoints (the Go usage reader exists), plus 429 retry-after values fed back as observed state.
  • Time-of-day prices: for example the Alibaba Token Plan night discount, 22:00-08:00 UTC+8 (owner-provided; read it from the provider docs or catalog when published, otherwise owner config with the source noted).
  • Job kind: lead, implementation worker, review, mechanical or bulk, benchmark. These are the Lead picks the right model for each job #176 roles and policy.
  • Model capability: from the live catalog (window, tools, images) and the job's needs.
  • Owner policy (user settings): fallback order, preferred pools per job kind, which jobs may wait for a cheaper window, and budget pools (#1388).

Behaviour

  1. Per request or job: pick the best available model for the job kind from pools that are not exhausted or near their limit, cheapest first among equals.
  2. Fail over at once on quota exhaustion (a long retry-after means exhausted, oxstack/ox-llm#2109) to the next pool in the owner's order, and record why. Never stall a goal on one dead pool.
  3. Shift deferrable work (benchmarks, bulk triage and reviews, nightly jobs) into discount windows, with a deadline so it never waits for ever.
  4. Keep a reserve of each pool for the lead itself.
  5. Show it: oxa usage and the lead board list each pool's state, the current choice and why. Every switch is logged with the reason.

Related

#100 (budget pools as owner config), #176 (model per job), #95 (usage windows in lead), oxstack/ox-llm#2109 (long retry-after is quota exhaustion), #84 (model per role), the round-2 "live providers" group (live provider facts).

Owner note: build it when OpenCode Go is back, so three pools can be compared.

Activity

  1. added
    enhancement
    on Nov 20, 2026
  2. n0rpan commented on Nov 20, 2026

    @n0rpan
    ContributorAuthor

    Owner 2026-11-20: time windows and prices must come from the provider, or else be user settings edited in a smart UI. Never a hard-coded table.

    What Alibaba publishes today: docs only, no API seen. The billing docs define night hours as 22:00-08:00 (UTC+8, billing time).

    • Personal Token Plan: 60% off credit use for qwen3.8-max and qwen3.8-flash.
    • Team Token Plan: 50% off for deepseek-v4-pro-0813, deepseek-v4-flash-0731, deepseek-v4.1-flash and deepseek-v4.1-flash-1017.
    • The marketing pages give other figures for other promotions.

    So the design is:

    1. Observed first. If the plan reports credits used per request or in its usage view, oxa measures the real multiplier per model and hour itself (a live fact, cached). That beats any document.
    2. Owner settings in a smart UI (lead web and oxa usage). A per-pool time-window editor: window, time zone, models, multiplier, and a source link with the date it was last checked. It is prefilled from the provider docs as a suggestion the owner accepts. It flags "observed differs from configured" when 1. disagrees.
    3. Nothing assumed. With no observed or configured value, the price is unknown and recorded as uncertain (same rule as unknown pricing today).
  3. n0rpan commented on Nov 20, 2026

    @n0rpan
    ContributorAuthor

    Owner screenshot of the Alibaba Model Studio console, 2026-11-20 (My Subscriptions): the night discount is shown per model as tags in the subscription view:

    • deepseek-v4.1-flash-1017, deepseek-v4.1-flash: "50% Off Nights"
    • deepseek-v4-pro-0813: "Limited-time Night 50% Off"
    • auto, qwen3.8-max: "40% Off Nights"
    • qwen4-max-preview: "Limited-Time 80% Off" (not night-bound)
    • qwen4-max: none.

    So the provider has the data in machine form behind its console, but the plan key's OpenAI-compatible /models is what oxa uses today. oxa's cache keeps only id, context and output from it, so the raw fields are not known yet.

    To check when this is built, in order:

    1. Do the raw GET /compatible-mode/v1/models items carry any pricing or discount fields? If yes, read them (live, cached).
    2. Does a read-only Alibaba Cloud OpenAPI (Model Studio subscription or plan endpoint, with a RAM AccessKey limited to read) return the same per-model tags? If yes, it is an optional second credential the owner can add; it is never required.
    3. Otherwise, use the observed credit multiplier, or the owner-set windows in the UI prefilled from the docs (see the comment above).
  4. transferred this issue fromon Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions