Skip to content

fix(4.x): Zen member budgets and Ollama balance API - #328

Merged
slkiser merged 3 commits into
release/4.xfrom
fix/4x-zen-ollama
Oct 15, 2026
Merged

slkiser merged 3 commits into
release/4.xfrom
fix/4x-zen-ollama

Conversation

@slkiser

@slkiser slkiser commented Oct 15, 2026

Copy link
Copy Markdown
Owner

Summary

Backports two provider fixes from main to the 4.x (OpenCode 1) line.

  • OpenCode Zen: OpenCode Console retired budgets/org (it now returns 409), so the monthly budget was missing. Zen now reads the signed-in member's budget from policies/members/{account id} and shows the most restrictive applicable monthly budget, including a shared workspace cap, with its reset at 00:00 UTC on the 1st of next month. If a budget can't be safely evaluated (model filters, per-model limits, missing amounts), it uses the credit limit with no error line, and /quota_status shows a member_budget_note. The account id comes from OpenCode 1's active Console account and never appears in error or status text. Backport of fix(opencode-zen): use applicable member budget #322 by @vmvarela.
  • Ollama Cloud: /api/usage no longer returns limits, so Ollama showed "no usable usage data". It now reads GET https://ollama.com/api/balance with a Bearer key: Session and Weekly with reset times on older plans, a Monthly row for included credits on credit plans, and Purchased: $X.XX left when purchased credit remains.

Linked Issue

Refs #320, refs #321.

OpenCode Validation

  • Current production released OpenCode version tested: OpenCode 1.19.0 (opencode-ai). The Zen account id was checked against its source (packages/opencode/src/account/account.ts at v1.19.0): account.id is the Console user id from GET /api/user, the id the members route expects.
  • Why this version is relevant to the fix: the 4.x line is for OpenCode 1 users.

Before-and-after evidence

Not applicable for screenshots: no live Console or Ollama account was available, so both fixes are covered by recorded replies in tests. Row names and labels are unchanged except the new Purchased: $X.XX left row and the new Monthly row for Ollama credit plans.

Quality Checklist

  • I ran pnpm verify
  • This change is focused and avoids unrelated behavior changes
  • I updated or added tests when behavior changed
  • I updated docs when user-facing workflow, command, or config behavior changed
  • For provider changes, I followed Provider Changes, or this does not apply

slkiser and others added 3 commits October 15, 2026 01:58
OpenCode Console retired GET /api/budgets/org (it answers 409), so the
Zen monthly budget showed an error row. Read
GET /api/policies/members/{account id} for the signed-in Console user
instead.

- Carry the active account id from OpenCode's account table. OpenCode
  1 stores the Console user id there (the id from GET /api/user).
- Trust the member response only when its userID matches. Show the
  applicable monthly budget with the least remaining USD; a $0 member
  budget is a blocking 0% budget. Dollar amounts convert to the
  existing billing units.
- Member budgets reset at 00:00 UTC on the 1st of the next month.
- If any member budget cannot be safely evaluated (model filter,
  per-model limit, unmatched rule, missing amount), use no member
  budget: fall back to the credit limit with no error row, and
  /quota_status shows member_budget_note.
- Errors name policies/members without the account id; network errors
  redact the id and its URL encoding.
- The Zen cache identity includes the account.

Backport of 8e646e6, 8876945 and f15670d from main. 4.x has no
budgetSource field: a member budget is the only source that sets the
reset date, so the provider uses that to keep a $0 member budget.

Refs #320

Co-authored-by: Victor M Varela <vmvarela@gmail.com>
GET https://ollama.com/api/usage no longer returns limits, so Ollama
Cloud showed "returned no usable usage data". Read the documented
GET https://ollama.com/api/balance with a Bearer API key instead.

- Credit plans: a Monthly row with the included credits left and the
  period's end as its reset time.
- Legacy plans: Session and Weekly rows from remaining_percent, with
  their reset times.
- Purchased credits: a "Purchased: $25.00 left" row when there are
  some, or when Ollama returns nothing else.
- /quota_status lists the included, session, weekly and purchased
  values instead of the old usage fractions.

Backport of 15dfc70e2 from main. Docs keep the 4.x prose layout.

Refs #321
@slkiser
slkiser merged commit 03e7511 into release/4.x Oct 15, 2026
4 checks passed
@slkiser
slkiser deleted the fix/4x-zen-ollama branch October 15, 2026 23:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant