Skip to content

Add OpenCode Zen/Black usage (experimental cookie-based integration) #170

@davidarny

Description

@davidarny

Summary

Add OpenCode provider support in OpenUsage for:

  • Zen billing usage (balance, monthly usage/limit, reload settings)
  • Black rolling/weekly usage when available

Why

OpenCode does not currently expose a documented public billing/usage API for Zen API keys. Zen docs expose model/inference endpoints, not account billing endpoints.

Research

Public docs / endpoints

  • Zen docs: https://opencode.ai/docs/zen/
  • Documented endpoints are model/inference oriented (/zen/v1/models, /zen/v1/responses, /zen/v1/messages, /zen/v1/chat/completions)

Prior art

What we verified

Proposal

Implement OpenCode as experimental provider via authenticated dashboard payload parsing:

  1. Auth input: manual Cookie header (required), optional workspace ID override.
  2. Fetch billing page (/workspace/<id>/billing) and parse hydration payload.
  3. Map Zen metrics from billing.get payload:
    • current balance
    • monthly usage / limit
    • reload settings
  4. If Black subscription usage is present, map rolling/weekly usage + reset timers.
  5. Fail loudly with explicit parse/auth errors (no silent fallback).

Scope guardrails

  • No browser scraping automation in v1.
  • No reliance on hardcoded private _server IDs in v1.
  • Mark provider as experimental/fragile in UI/docs.

Acceptance Criteria

  • OpenCode plugin exists with manual cookie auth UX.
  • Parser covered with fixtures + regression tests for payload-shape drift.
  • Clear user-facing errors for expired cookie / parse failure.
  • README updated to include OpenCode support and experimental warning.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions