Skip to content

SDK session exits terminally when /api/oauth/usage returns 403 for a valid-inference OAuth token (sk-ant-oat01) #834

Description

@guyb1

Summary

When a jcode SDK session starts with an Anthropic OAuth token
(sk-ant-oat01-…, the kind minted by a Claude subscription sign-in) whose scopes
allow inference but NOT the usage endpoint, the SDK treats its startup usage
preflight as fatal and the session dies before the first message is ever sent to
the model.

What happens

  1. The SDK session starts normally.
  2. Because the credential is an OAuth token, the SDK runs its OAuth preflight:
    GET /api/oauth/usage plus GET /v1/models.
  3. Observed statuses from Anthropic:
    • GET /v1/models200 — the token is valid for inference
    • GET /api/oauth/usage403
  4. ~1.7s after session start, the session terminates.
  5. No /v1/messages call is ever attempted.

Expected behavior

A 403 from the usage endpoint is a cosmetic/quota-display concern. With
/v1/models returning 200 for the same credential, the SDK should log and skip
the failed preflight (degrade gracefully) and proceed to inference. A usage/quota
readout can show "unavailable" instead of tearing down the session.

Actual behavior

The failed usage preflight is treated as terminal: the session closes before any
inference call, so a credential fully capable of chat completions cannot be used
through the SDK at all.

Repro

  1. Obtain an Anthropic OAuth token (sk-ant-oat01-…) that can call /v1/messages
    / /v1/models but 403s on /api/oauth/usage.
  2. Start a session through the jcode SDK with that credential.
  3. Observe the session terminate immediately after the preflight, with no message
    call attempted.

Notes

  • Workaround: use a standard API key (sk-ant-api…) instead of the OAuth token.
  • Observed from outside the SDK, so internal naming of the preflight may differ.

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