Skip to content

Spike: review subscription and API key management against Anthropic's updated Agent SDK pricing and limits #855

Open

Description

@vybe

Summary

Anthropic recently updated pricing, rate limits, and usage tiers for the Claude API alongside the Agent SDK release. Trinity's subscription management (SUB-002) and API key handling (the use_platform_api_key flag, per-agent key injection, MCP key scoping) were designed against the previous model. This spike reviews what needs to change to stay aligned with the new limits and take advantage of any new capabilities the Agent SDK exposes.

Context

Trinity manages Anthropic API access in two ways:

  1. Platform key — a single Anthropic API key shared across all agents via the use_platform_api_key flag in agent_ownership
  2. Per-agent key — operators can inject their own ANTHROPIC_API_KEY via the credential system (CRED-002)

The Agent SDK introduces changes to rate limits (per-model, per-tier), usage-based billing signals, and potentially new key scoping semantics. Trinity's subscription layer (SUB-002, routers/subscriptions.py, services/subscription_service.py) may need updating to reflect new tier boundaries, and the platform key pooling strategy may need revisiting if per-key rate limits have changed significantly.

This also connects to the enterprise edition direction (#847) — understanding Anthropic's new limits informs how multi-tenant API key pooling should work at scale.

Acceptance Criteria

  • Document Anthropic's new pricing tiers and rate limits (per-model, per-tier, per-key) as they apply to Trinity's usage patterns
  • Identify whether the current platform-key-sharing model hits new rate limits at realistic fleet sizes (e.g. 30, 100, 200 agents)
  • Assess whether the Agent SDK exposes new API primitives (usage tracking, budget controls, key scoping) that Trinity should surface
  • Review services/subscription_service.py and routers/subscriptions.py — identify any hardcoded tier assumptions that need updating
  • Review agent_ownership.max_parallel_tasks and execution_timeout_seconds defaults against new rate limit shapes
  • Produce a short recommendation: what changes are required (blocking), what is nice-to-have, and what can be deferred

Technical Notes

Activity

  1. added
    priority-p2
    type-feature
    on May 15, 2026
  2. added
    theme-infrastructure
    on Jun 3, 2026
  3. added
    complexity-medium
    status-incubating
    on Jun 12, 2026
  4. vybe commented on Aug 7, 2026

    @vybe
    ContributorAuthor

    Partial input to this spike (2026-08-07) — findings from a docs review against current Anthropic documentation, relevant to the "does the Agent SDK expose usage/budget primitives" acceptance criterion:

    • Agent SDK: exposes no usage-tracking or limit-introspection primitives (no usage property, no limit-warning hook, nothing in init/result messages).
    • Admin/Usage & Cost API: covers API-key organizations only — no coverage of Claude subscription (OAuth) usage.
    • Subscription-side, two usable surfaces exist: the officially documented statusline rate_limits JSON (5h/7d used_percentage + resets_at, https://code.claude.com/docs/en/statusline.md) and the undocumented OAuth usage endpoint already validated by scripts/poc/test-subscription-usage.py (Feb 2026).
    • Hooks: StopFailure can match rate_limit/billing_error — fires post-failure only, so it's a graceful-exit surface, not a throttling one.

    Promoting to status-ready (operator call, 2026-08-07) — the subscription half of this spike now has concrete surfaces to review against.

  5. added
    status-ready
    and removed
    status-incubating
    on Aug 7, 2026
  6. vybe commented on Aug 14, 2026

    @vybe
    ContributorAuthor

    Partially answered — scoping note, 2026-08-14. Reviewed against the 2026-08-07 premise correction (posted on #471) during the usage-cluster reconciliation. Not closing; one AC is answered, the rest are not.

    Answered — AC 3 ("does the SDK/API expose new primitives — usage tracking, budget controls, key scoping — that Trinity should surface"): yes, two, both verified.

    1. The OAuth usage endpoint (GET /api/oauth/usage), proven by this repo's own POC scripts/poc/test-subscription-usage.py — returns 5h/7d utilization, per-model limits, extra-usage status.
    2. Claude Code's officially documented statusline rate_limits JSON — five_hour / seven_day used-percentage plus reset times, zero extra API calls.
      The consuming work is already filed: feat: Subscription usage observability — 5h/7d usage dashboard, per-agent breakdown, and rate-limit event history #471 (data layer, now P1), trinity-enterprise#259 (tile), trinity-enterprise#351 (agent self-awareness). Nothing further needed from this spike on that axis.

    Still open and still worth the spike — the fleet-scale half nobody has looked at: new tier boundaries and per-key rate limits at realistic fleet sizes (30 / 100 / 200 agents), whether platform-key pooling survives them, hardcoded tier assumptions in subscription_service.py / routers/subscriptions.py, and the max_parallel_tasks / execution_timeout_seconds defaults against the new limit shapes.

    Suggest re-titling to the remaining scope when someone picks it up, so it does not read as still-asking the answered question.

  7. vybe commented on Aug 19, 2026

    @vybe
    ContributorAuthor

    Spike partially executed as a side effect of the #471 build gate (2026-08-19) — the provider-signal half of this spike now has real payloads:

    1. GET https://api.anthropic.com/api/oauth/usage with a stored claude setup-token token (sk-ant-oat01-) → 403 permission_error: OAuth token does not meet scope requirement user:profile. Mechanism established: setup tokens are inference-scoped; the endpoint requires user:profile, which only interactive-login tokens carry. Any design assuming Trinity can poll that endpoint with stored credentials is dead on arrival (confirms Show Claude subscription usage without metered cost #2170's post-mortem with the exact reason).

    2. POST /v1/messages under the same token returns the unified rate-limit header set (anthropic-ratelimit-unified-{5h,7d}-utilization/-reset/-status, representative-claim, overage status/reason) — real remaining-budget data, per subscription, centrally reachable. feat: Subscription usage observability — 5h/7d usage dashboard, per-agent breakdown, and rate-limit event history #471 builds its headroom layer on this channel (micro-ping probe + source: anthropic|observed contract).

    Remaining for this spike: the pricing/limits policy review against the Agent SDK terms, and whether an officially documented usage surface for setup tokens appears (which would retire the probe).

  8. added
    status-incubating
    and removed
    status-ready
    on Sep 11, 2026
  9. added
    status-ready
    and removed
    status-incubating
    on Sep 24, 2026
  10. vybe commented on Nov 24, 2026

    @vybe
    ContributorAuthor

    This spike is now the blocker for a customer-facing answer, not just an internal alignment check.

    Operators are reaching the Connect Claude step and asking, before they buy anything, roughly what a handful of agents will consume so they can pick the right plan tier — and nothing published answers it. Observed consumption and the per-agent cost breakdown in Settings → Integrations answer it only in hindsight, after a plan is already bought, and the weekly-limit alert warns at 75% of a window the operator has already committed to.

    The acceptance criteria here already cover the two inputs that answer would need — current per-tier pricing and rate limits as they apply to Trinity's usage patterns, and whether the model holds at realistic fleet sizes. I have filed the publishing half separately as #4748 (a "choosing a Claude credential" section plus sizing guidance in the credential guides) and marked it as depending on this spike for the numbers, deliberately rather than guessing a figure ahead of it.

    Two things have moved since this was last updated (2026-09-24) and are worth folding into the spike's scope when it runs:

    • Programmatic use of a consumer subscription now draws on a separate monthly credit allowance, distinct from the interactive 5h/7d windows the subscription docs describe. If that holds, our published model of subscription consumption — two fixed windows with scheduled resets — is incomplete for exactly the automated, unattended pattern every Trinity agent runs, and the sizing answer differs by credential in a way nothing surfaces today.
    • Anthropic's terms for using Pro/Max subscriptions with third-party tools have changed more than once this year. That half is explicitly not this issue — it is a provider-terms question, tracked outside the public tracker, and the evaluator security page §5 already states that Trinity's documentation does not address provider terms. Named here only so the spike does not quietly answer it on our behalf while documenting the limits.

    Also for the record, verified on dev at c62030cf: the capacity defaults this issue asks to review are unchanged — max_parallel_tasks default 3 (db/schema.py, db/agent_settings/resources.py), fleet ceiling default 10. Since #1027 the backend's own small model calls go through services/model_gateway.py and a job attributed to a subscription-mode agent consumes that agent's subscription, which is consumption the original framing of this issue (platform key only, per-agent injection) predates.

    No priority change requested.

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

    complexity-mediumpriority-p2status-readytheme-infrastructuretype-feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions