Harden OpenAI-compatible AI adapter requests#488
Conversation
Greptile SummaryThis PR hardens the five OpenAI-compatible AI adapters (Groq, DeepSeek, Mistral, xAI, Cerebras) by normalizing trailing slashes from configured base URLs and redacting provider API keys from error messages before surfacing them to callers.
Confidence Score: 5/5Safe to merge — the redact-before-slice ordering is correct across all five adapters, and the boundary-case tests validate the key behaviour. All five adapters correctly call redact on the full response body before truncating to 200 characters, so no API key fragment can survive into the error message. URL normalization is a simple regex strip. The duplicated helper functions are a maintenance concern but carry no runtime risk. No files require special attention. The only note is that Important Files Changed
Sequence DiagramsequenceDiagram
participant Caller
participant Adapter
participant chatCompletionsUrl
participant fetch
participant redact
Caller->>Adapter: generate(ctx, prompt, opts, config)
Adapter->>chatCompletionsUrl: baseUrl (may have trailing slash)
chatCompletionsUrl-->>Adapter: normalized URL (/v1/chat/completions)
Adapter->>fetch: POST normalized URL
alt res.ok
fetch-->>Adapter: 2xx JSON response
Adapter-->>Caller: "{ text, model, tokens }"
else !res.ok
fetch-->>Adapter: non-2xx response
Adapter->>redact: res.text() + apiKey
redact-->>Adapter: sanitised body (key replaced with [redacted])
Adapter->>Adapter: .slice(0, 200)
Adapter-->>Caller: throw Error("Provider STATUS: truncated-sanitised-body")
end
Reviews (2): Last reviewed commit: "Redact adapter errors before truncating" | Re-trigger Greptile |
Summary
Tests