feat(coding-agent): add Vercel AI Gateway attribution (#5798)

This commit is contained in:
Ramiz Wachtler
2026-06-16 09:37:37 +02:00
committed by GitHub
parent b0c8f65ffa
commit f8a77f47f2
2 changed files with 19 additions and 0 deletions

View File

@@ -7,6 +7,7 @@ const NVIDIA_NIM_HOST = "integrate.api.nvidia.com";
const CLOUDFLARE_API_HOST = "api.cloudflare.com";
const CLOUDFLARE_AI_GATEWAY_HOST = "gateway.ai.cloudflare.com";
const OPENCODE_HOST = "opencode.ai";
const VERCEL_GATEWAY_HOST = "ai-gateway.vercel.sh";
function matchesHost(baseUrl: string, expectedHost: string): boolean {
try {
@@ -33,6 +34,10 @@ function isCloudflareModel(model: Model<Api>): boolean {
);
}
function isVercelGatewayModel(model: Model<Api>): boolean {
return model.provider === "vercel-ai-gateway" || matchesHost(model.baseUrl, VERCEL_GATEWAY_HOST);
}
function getDefaultAttributionHeaders(
model: Model<Api>,
settingsManager: SettingsManager,
@@ -61,6 +66,13 @@ function getDefaultAttributionHeaders(
};
}
if (isVercelGatewayModel(model)) {
return {
"http-referer": "https://pi.dev",
"x-title": "pi",
};
}
return undefined;
}

View File

@@ -196,6 +196,13 @@ describe("createAgentSession provider attribution headers", () => {
expect(headers?.["X-OpenRouter-Categories"]).toBe("provider-category");
});
it("adds default attribution headers for Vercel AI Gateway models", async () => {
const headers = await captureHeaders(createModel("vercel-ai-gateway", "https://ai-gateway.vercel.sh/v1"));
expect(headers?.["http-referer"]).toBe("https://pi.dev");
expect(headers?.["x-title"]).toBe("pi");
});
it("adds default attribution headers for direct NVIDIA NIM endpoints", async () => {
const headers = await captureHeaders(createModel("custom-nim", "https://integrate.api.nvidia.com/v1"));