How to keep credentials out of recorded AI API test fixtures
Redact authorization headers and equivalent credential fields before writing a recording. Preserve the protocol behavior with synthetic values and check the exact file that will be shared.
Example
A development test records successful requests for replay. The response body is harmless but the recording includes the authorization header that was sent upstream.
What to do
- Identify the fields used to carry keys or sessions, including headers, query parameters and client metadata. Use a scoped test identity while recording.
- Strip current values before persistence. Replace them with a fixture identifier if the replay framework needs to match authentication shape.
- Scan the recording and any attached logs before committing. Add a fixture containing a recognizable fictional credential to test the sanitization step.
How to verify
The test still replays successfully and the fictional credential is absent from all persisted artifacts.
Limits
Vendor wrappers and transports can store their own debug logs. Check those outside the primary recording directory.