Enhance AI proxy response handling by adding X-Generation-Id header

- Updated the response headers in the AI proxy integration to include the X-Generation-Id if present in the response from the target URL.
- Ensured that response headers are explicitly typed for better clarity and maintainability.
This commit is contained in:
Aadesh Kheria 2026-07-16 16:00:44 -07:00
parent 299ac703b7
commit adf84fc29b

View File

@ -34,10 +34,14 @@ async function proxyToOpenRouter(req: NextRequest, options: { params: Promise<{
const response = await fetch(targetUrl, { method: req.method, headers: forwardHeaders, body });
const responseHeaders = {
const responseHeaders: Record<string, string> = {
"Content-Type": response.headers.get("Content-Type") ?? "application/json",
"Cache-Control": "no-store",
};
const generationIdHeader = response.headers.get("X-Generation-Id");
if (generationIdHeader != null) {
responseHeaders["X-Generation-Id"] = generationIdHeader;
}
const passthrough = () => new Response(response.body, { status: response.status, headers: responseHeaders });