Repository navigation
[AISAGE-733] feat(ai-gateway): errors-only request logging and API request log filters - #8060
Merged
Merged
Conversation
johnnyeric
approved these changes
Oct 19, 2026
This was referenced Oct 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Changes to the API Request Log tab at
/admin/gateway?tab=api-request-log.Errors-only request logging opt-ins
When creating a request logging opt-in, you can now set Log to All requests (the default) or Errors only. The active opt-ins table has a new Log column.
What gets logged. An errors-only opt-in writes an
api_request_logrow and its R2 bodies only for:This matches the download's existing "Errors only" filter. The response body is still buffered, because tool-call errors can only be detected after the body is read. Successful responses are dropped before anything is uploaded to R2 or inserted.
Overlapping opt-ins. When an account opt-in and an organization opt-in both match, the broader one wins: if either logs all requests, all requests are logged.
Existing data.
errors_onlyis a new field in theai_gateway_request_logging_opt_ins.opt_insJSON. It defaults tofalse, so existing opt-ins keep logging all requests. No migration is needed.Code changes.
isDynamicallyOptedIntoRequestLoggingis replaced bygetDynamicRequestLoggingMode, which returns'all' | 'errors_only' | null.Download filters
organization_idexactly and adds_org-<id>to the ZIP filename.anthropic/. LIKE wildcards (%,_,\) in the input are escaped, so they match literally.Limitations
Verification
jest -iforrequest-logging-opt-ins.test.tsandrewriteModelResponse.test.ts(136 passed). New tests check that an errors-only opt-in:Legacy opt-ins without
errors_onlyparse as logging all requests.jest -i src/app/admin/api/api-request-log/download(40 passed). New tests cover:%/_in the prefix,pnpm --filter web --filter ai-gateway --filter @kilocode/web-shared typecheckoxlint --config .oxlintrc.jsonon the changed files, pluspnpm format:changedandgit diff --checkManually check the admin UI in a browser
Visual Changes
e.g. anthropic/.Reviewer Notes
The errors-only check runs inside the existing
after()callback increateRequestLogCapture(packages/web-shared/src/lib/ai-gateway/rewriteModelResponse.ts), before the R2 upload.