GeezerVison is showing github.com — feat(core): read OpenCode Console usage limits and classify budget refusals by adamdotdevin · Pull Request #58694 · anomalyco/opencode
Conversation
adamdotdevin
commented
Oct 24, 2026
•
edited by opencode-agent
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
This is the data layer for the usage limits designs (Figma: Desktop Q4 2026 → Usage), which add a Usage limits dialog, a header indicator, timeline notices and model picker usage. The UI PRs build on this one and target beta.
Usage limits endpoint
GET /api/experimental/usage/limits (client.usage.limits({ location })) returns the OpenCode Go allowance and Console budgets of the OpenCode Console workspace the location is signed in to. It returns data: null when the location isn't signed in.
{
"workspace": { "id": "wrk_…", "name": "Anomaly", "usageURL": "https://opencode.ai/console/wrk_…/activity/overview" },
"go": { // only where the member subscribes to Go
"rolling": { "percent": 42, "limited": false, "resetsAt": 1792890000000 },
"weekly": { "percent": 18, "limited": false, "resetsAt": 1793232000000 },
"monthly": { "percent": 100, "limited": true, "resetsAt": 1793491200000 }
},
"budgets": [
{
"id": "rule_…", "limit": 20, "spent": 15,
"scope": "each", "per": "model", // per member or combined; across the set or per model
"coverage": "models", // "all": every model and billable service
"models": [{ "providerID": "opencode", "modelID": "gpt-6-astra", "name": "GPT-6 Astra", "spent": 15 }],
"vendors": ["OpenAI"], // what the budget counts: vendors by name,
"inputPriceAtLeast": 3, // a price floor (USD per 1M input tokens),
"picked": false, // or models picked one by one
"shared": false, // the entire workspace pools it
"resetsAt": 1793491200000
}
]
}
- Core's
UsageLimits service resolves the location's active OpenCode Console credential and reads two endpoints in parallel:
- Console's
GET /api/policies/current-budgets, with x-org-id.
- Go's
GET /zen/go/v1/usage on the Console's origin, with x-opencode-org-id.
- Console refuses budgets to a service account's key and Go refuses non-subscribers (both 403). Those mean "nothing to show", not errors. Other failures return 503.
- Budget models carry OpenCode's own provider and model IDs, so the model picker can find limited models.
- The Console URL and auth headers move from the OpenCode Console plugin into
ConsoleAccess, so the plugin and the new service share one implementation, including the retired-host rewrite.
Budget refusals
Console now refuses requests over a budget with a typed BudgetLimitError, which says what the budget covers. In Google's envelope, that's in an ErrorInfo detail.
packages/ai classifies it as quota, so it isn't retried as a rate limit.
toSessionError reports provider.model-budget-limit for a budget on the requested model and provider.budget-limit for one on all model use. This matches the two timeline notices in the design.
Depends on
anomalyco/opencode-console#4283 adds these fields and errors. It's merged to Console dev and deployed there; production gets it with the next promotion. anomalyco/opencode-console#4288 adds vendors, inputPriceAtLeast and picked, which the revised designs use to say what a budget counts. Until then, production Console's current-budgets lacks the new fields. Members with an all-spend budget would get a 503 from this endpoint, while members without budgets are unaffected. Nothing calls the endpoint until the UI PRs.
Tests
packages/core/test/usage-limits.test.ts: the requests sent to Console and Go (headers per service), mapping, 403s as nothing to show, and failures as unavailable.
packages/server/test/usage.test.ts: the route, null for a signed-out location, and a 503 for an unavailable Console.
packages/core/test/session-error.test.ts: model versus all-spend budget refusals, in both envelopes.
packages/ai/test/provider-error.test.ts: BudgetLimitError classifies as quota, in both envelopes.
- Each new assertion was checked to go red by breaking the behaviour it names.
bun run check passes, and so do the Console plugin and client suites.
Verified against dev Console
I ran this branch with isolated state, signed in to a temporary dev workspace by device login (--answer server=https://dev.opencode.ai/console). That workspace had a combined all-spend budget for the entire workspace and a per-member budget on DeepSeek V4 Flash and Grok 4.7.
opencode api experimental.usage.limits returned both budgets, with the expected coverage, shared, models (by OpenCode provider ID), limits, spend and reset time. There was no Go section, because the live Go endpoint refuses (403) a workspace without a subscription.
- At $0 on the model budget, a DeepSeek V4 Flash prompt failed straight away with
provider.model-budget-limit. Console's body was BudgetLimitError with metadata: { coverage: "models", resetsAt: "2026-11-01T00:00:00.000Z" }.
- At $0 on the workspace budget, the same prompt failed with
provider.budget-limit (coverage: "all").
- Not checked live: the Google envelope, because no Gemini model is routed on dev. The Console and OpenCode unit tests above cover it.
Added by the opencode bot (AI-generated).
Related: #57072, #42776, #49693
Public API: adds vendors, inputPriceAtLeast and picked to UsageLimits.Budget in GET /api/experimental/usage/limits (backwards compatible)
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
…fusals
Adds GET /api/experimental/usage/limits (client.usage.limits): the OpenCode Go
allowance and Console budgets of the OpenCode Console workspace a location is
signed in to, or null when it isn't. Core's UsageLimits service reads Console's
current budgets and Go's usage endpoint with the location's Console credential.
Console now refuses requests over a budget with BudgetLimitError. It classifies
as quota rather than a retryable rate limit, and the session error says whether
a budget on the requested model (provider.model-budget-limit) or one on all
model use (provider.budget-limit) refused it.
The Console URL and auth headers move from the OpenCode Console plugin into
ConsoleAccess so both use one implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks sound. I ran the server from source: the new route returns data: null for a location that isn't signed in. The new core, ai, server and client tests pass, and tsc -b is clean on core (with tests), server and client. I couldn't exercise a signed-in Console without credentials; the mocked tests cover the requests, the mapping and the 403s.
Public API: adds GET /api/experimental/usage/limits (experimental.usage.limits, client.usage.limits({ location })), the UsageLimits.* schemas in @opencode/schema/usage-limits and the OpenAPI spec, and two new session error types, provider.budget-limit and provider.model-budget-limit. Responses that used to come back as provider.quota now get one of these when the body contains BudgetLimitError. Everything is additive. The only behaviour change: anything matching on provider.quota for Console budget refusals will now see the new types.
One concern, inline: if either upstream read fails, the whole endpoint fails.
Related: #57072, #42776, #49693
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
const workspaceID = credential.metadata?.orgID
|
|
|
if (typeof workspaceID !== "string") return undefined
|
|
|
const server = ConsoleAccess.server(credential)
|
|
|
const [budgets, go] = yield* Effect.all(
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is all-or-nothing: a Go /zen/go/v1/usage outage hides the member's budgets, and a budgets decode failure hides Go. The second case will happen against production Console until #4283 is promoted, for anyone with an all-spend budget. Since the two reads are independent, could each one degrade on its own? For example, leave out go or return no budgets, and only return a 503 when both fail. That way the header indicator keeps showing whatever data it does have.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Budgets carry the vendors (by name), input price floor and whether models are
picked one by one, from anomalyco/opencode-console#4288, so the app can name a
budget "Anthropic models" or "$3+ per 1M input" in the member's language.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new fields map correctly. The updated core and server tests pass, and tsc -b is clean on core, server and client. The earlier point about the endpoint being all-or-nothing isn't addressed yet.
Public API: adds vendors: string[], inputPriceAtLeast?: Money.USDPerMillionTokens and picked: boolean to UsageLimits.Budget, both in the experimental GET /api/experimental/usage/limits response and in the OpenAPI spec. These are additive, and the endpoint is unreleased.
One new concern, inline: the new fields are required when decoding Console's response.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
spentDollars: Schema.optional(Schema.Finite),
|
|
|
}),
|
|
|
),
|
|
|
vendors: Schema.Array(Schema.Struct({ id: Schema.String, name: Schema.String })),
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vendors and picked are required here, so any Console without anomalyco/opencode-console#4288 fails to decode every budget, not only all-spend ones. Until it's deployed, any member with a budget at all would get a 503. Could these decode as optional, with [] and false as defaults, so the endpoint doesn't depend on that deploy?
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Oct 24, 2026
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Oct 25, 2026
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.
|