Skip to content

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

Closed

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/models → 200 — the token is valid for inference
    • GET /api/oauth/usage → 403
  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.

Activity

  1. 1jehuang commented on Aug 7, 2026

    @1jehuang
    Owner

    Thanks for the clear report. Could you share the SDK package and version, a minimal startup script, and the terminal error or stack trace emitted when the session exits? Please redact the token itself. That will let us identify whether the fatal path is in the SDK client, daemon startup, or usage preflight.

    --- — Jcode agent (automated triage), on behalf of @1jehuang

  2. added
    bug
    needs-info
    triage: unclear
    on Aug 7, 2026
  3. guyb1 commented on Aug 7, 2026

    @guyb1
    Author

    Sure , details: @1jehuang

    • Package/version: npm jcode SDK 1.1.0, which ships binary v0.67.1. That's the combination that dies. One extra data point that may help you bisect: we also observed a run where the harness self-fetched jcode-linux-aarch64.tar.gz v0.68.0 from GitHub releases at runtime, and that version appears to survive the same 403 — so this looks like it's already fixed (or at least changed) between v0.67.1 and v0.68.0, and the fatal path is likely in the preflight handling the SDK-pinned binary uses.
    • Setup: nothing exotic - a headless SDK session started with the sk-ant-oat01-… credential as the only auth. No custom config beyond the credential.
    • Error/stack trace: I don't have one, and that's a limitation of how we observed this: the harness runs inside a container behind a TLS-terminating proxy, which is where the statuses came from (/v1/models → 200, /api/oauth/usage → 403, then session teardown ~1.7s after start with no /v1/messages ever attempted). The process's own stderr wasn't captured. Happy to re-run with stderr captured if the wire-level picture isn't enough to locate it.
  4. 1jehuang commented on Aug 8, 2026

    @1jehuang
    Owner

    Confirmed from the reporter’s version data that this is a bundled-runtime problem in SDK 1.1.0 (jcode v0.67.1), not a current-source regression: the same credential survives with v0.68.0. I prepared SDK 1.2.0 in commit 388d424 so the next SDK publication can bundle the current released runtime instead of v0.67.1. The TypeScript SDK check suite passes (40/40). This should remain open until 1.2.0 is published and verified from npm.

  5. added
    triage: fixed-pending-release
    autonomous: likely
    and removed
    triage: unclear
    needs-info
    on Aug 8, 2026
  6. 1jehuang commented on Aug 8, 2026

    @1jehuang
    Owner

    Publication follow-up: SDK 1.2.0 is prepared and the full SDK suite passes (40/40), but the npm release workflow failed at the first platform runtime package:

    https://github.com/1jehuang/jcode/actions/runs/31281171957

    npm accepted the GitHub provenance statement, then returned E404 for @1jehuang/[email protected], which is npm's response when the workflow is not authorized as a trusted publisher for that package. The main @1jehuang/jcode-sdk trusted-publisher setup does not grant access to its six platform packages.

    To unblock 1.2.0, configure .github/workflows/publish-typescript-sdk.yml as a trusted publisher for each existing platform package (darwin-arm64, darwin-x64, linux-arm64, linux-x64, win32-arm64, win32-x64), then rerun the workflow with jcode_release_tag=v0.72.0. No package was published by the failed run.

  7. github-actions commented on Aug 12, 2026

    @github-actions
    Contributor

    Released in v0.75.5. Run jcode update to get it.

  8. removed
    triage: fixed-pending-release
    on Aug 12, 2026
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

    autonomous: likelybug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions