Skip to content

Conversation

@dannykopping
Copy link
Collaborator

@dannykopping dannykopping commented Dec 31, 2025

Logs the raw HTTP requests to and responses from AI providers' APIs.

$ tree /tmp/anthropic/
/tmp/anthropic/
├── claude-haiku-4-5-20251001
│   ├── 1768744410613-bb8e4048-8ea2-4aee-a58d-25027b962bf8.req.txt
│   ├── 1768744410614-bb8e4048-8ea2-4aee-a58d-25027b962bf8.resp.txt
│   ├── 1768744410615-e1f338a1-7ae9-4ccf-b898-fc3fbc25124e.req.txt
│   └── 1768744410616-e1f338a1-7ae9-4ccf-b898-fc3fbc25124e.resp.txt
└── claude-opus-4-5-20251101
    ├── 1768744410613-024f344e-c75a-46ea-abfb-e45e117e121a.req.txt
    ├── 1768744410614-024f344e-c75a-46ea-abfb-e45e117e121a.resp.txt

@dannykopping dannykopping requested a review from pawbana December 31, 2025 12:53
@dannykopping dannykopping force-pushed the dk/request-logging-redux branch from beb1aca to d021c47 Compare January 15, 2026 13:06

resp, err := next(req)
if err != nil {
return resp, err
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about it but maybe it be useful to have "err" file with error?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's leave this for a future enhancement, ok?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, could you please create an issue about it?

reqDumpData, err := os.ReadFile(reqDumpFile)
require.NoError(t, err, "request dump file should exist")
require.Contains(t, string(reqDumpData), "POST ")
require.Contains(t, string(reqDumpData), "Host:")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add check like require.Contains(t, string(reqDumpData), string(reqBody))

and similar for response

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This forced me to confront the fact that map keys were not stably sorted. Thanks 👍

Copy link
Collaborator Author

dannykopping commented Jan 17, 2026


for _, key := range headerKeys {
// Skip Content-Length since we write it explicitly above with the pretty-printed body length.
if key == "Content-Length" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Host could also be skipped

Comment on lines +137 to +152
// Sort header keys for deterministic output.
headerKeys := make([]string, 0, len(resp.Header))
for key := range resp.Header {
headerKeys = append(headerKeys, key)
}
slices.Sort(headerKeys)

for _, key := range headerKeys {
_, sensitive := sensitiveResponseHeaders[key]
for _, value := range resp.Header[key] {
if sensitive {
value = redactHeaderValue(value)
}
fmt.Fprintf(&headerBuf, "%s: %s\r\n", key, value)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks copy-pasty from lines 105-124.

return []aibridge.Provider{provider.NewOpenAI(openaiCfgWithAPIDump(addr, apiKey, dumpDir))}
},
createRequestFunc: createOpenAIChatCompletionsReq,
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add test case for responses

@dannykopping dannykopping force-pushed the dk/request-logging-redux branch from a93b2ec to e4c2a82 Compare January 19, 2026 17:02
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.

2 participants