Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/forward-gateway-supported-urls.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"ai-gateway-provider": patch
---

Forward supported URL metadata from wrapped provider models.
8 changes: 4 additions & 4 deletions packages/ai-gateway-provider/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ export class AiGatewayChatLanguageModel implements LanguageModelV3 {
readonly specificationVersion = "v3";
readonly defaultObjectGenerationMode = "json";

readonly supportedUrls: Record<string, RegExp[]> | PromiseLike<Record<string, RegExp[]>> = {
// No URLS are supported for this language model
};

readonly models: InternalLanguageModelV3[];
readonly config: AiGatewaySettings;

get supportedUrls(): Record<string, RegExp[]> | PromiseLike<Record<string, RegExp[]>> {
return this.models[0]?.supportedUrls ?? {};
}

get modelId(): string {
if (!this.models[0]) {
throw new Error("models cannot be empty array");
Expand Down
26 changes: 26 additions & 0 deletions packages/ai-gateway-provider/test/supported-urls.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type { LanguageModelV3 } from "@ai-sdk/provider";
import { describe, expect, it } from "vitest";
import { createAiGateway } from "../src";

describe("supportedUrls", () => {
it("forwards supported URLs from the wrapped model", async () => {
const supportedUrls = {
"application/pdf": [/^https:\/\/example\.com\/.*$/],
"image/*": [/^https:\/\//],
};
const wrappedModel = {
modelId: "test-model",
provider: "test-provider",
specificationVersion: "v3",
supportedUrls,
} as unknown as LanguageModelV3;

const aigateway = createAiGateway({
accountId: "test-account-id",
apiKey: "test-api-key",
gateway: "test-gateway",
});

await expect(await aigateway(wrappedModel).supportedUrls).toBe(supportedUrls);
});
});