Skip to content

add more context to ai-gateway jwt#73315

Open
alex-m-brown wants to merge 1 commit into
stagingfrom
ai-gateway-observability/add-context-to-jwt
Open

add more context to ai-gateway jwt#73315
alex-m-brown wants to merge 1 commit into
stagingfrom
ai-gateway-observability/add-context-to-jwt

Conversation

@alex-m-brown

@alex-m-brown alex-m-brown commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Adds five new claims to the AI Gateway access-token JWT, pulled from the aichatContext the client already sends:

  • client_type
  • level_id (from currentLevelId)
  • script_id
  • channel_id
  • lesson_id

These claims let the AI Gateway Worker attach curriculum context (level, lesson, script, channel) to Sentry traces, so we can slice telemetry by lesson and correlate a request back to a specific issuance event. The token interface on the worker side already declared channel_id and level_id as required fields, but they were never actually issued — this fixes the mismatch and adds the other three while we're touching the issuer.

Links

  • Jira: SL-1749
  • Companion PR (ai-gateway): code-dot-org/ai-gateway#37 — reads these claims and attaches them as context.* attributes on the root Sentry span

Testing story

  • Manual: requested a token from /ai_gateway/access_token with a real aichatContext, decoded the returned JWT, confirmed all five new claims are populated with the values the client sent.
Screenshot 2026-06-17 at 3 17 37 PM

Note: Lesson_id is in the AIchatContext Type, but it isn't currently passed through. we can add this in a follow-up if useful.

Screenshot 2026-06-17 at 2 21 36 PM
  • Verified can_access_aichat_chat_completion? still gates correctly (no behavior change to the access check — only refactored to a local var).

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