UNPKG

ai-gateway-provider

Version:

AI Gateway Provider for AI-SDK

64 lines (61 loc) 2.71 kB
import { LanguageModelV2 } from '@ai-sdk/provider'; import { FetchFunction } from '@ai-sdk/provider-utils'; declare class AiGatewayInternalFetchError extends Error { } declare class AiGatewayDoesNotExist extends Error { } declare class AiGatewayUnauthorizedError extends Error { } type InternalLanguageModelV2 = LanguageModelV2 & { config?: { fetch?: FetchFunction | undefined; }; }; declare class AiGatewayChatLanguageModel implements LanguageModelV2 { readonly specificationVersion = "v2"; readonly defaultObjectGenerationMode = "json"; readonly supportedUrls: Record<string, RegExp[]> | PromiseLike<Record<string, RegExp[]>>; readonly models: InternalLanguageModelV2[]; readonly config: AiGatewaySettings; get modelId(): string; get provider(): string; constructor(models: LanguageModelV2[], config: AiGatewaySettings); processModelRequest<T extends LanguageModelV2["doStream"] | LanguageModelV2["doGenerate"]>(options: Parameters<T>[0], modelMethod: "doStream" | "doGenerate"): Promise<Awaited<ReturnType<T>>>; doStream(options: Parameters<LanguageModelV2["doStream"]>[0]): Promise<Awaited<ReturnType<LanguageModelV2["doStream"]>>>; doGenerate(options: Parameters<LanguageModelV2["doGenerate"]>[0]): Promise<Awaited<ReturnType<LanguageModelV2["doGenerate"]>>>; } interface AiGateway { (models: LanguageModelV2 | LanguageModelV2[]): LanguageModelV2; chat(models: LanguageModelV2 | LanguageModelV2[]): LanguageModelV2; } type AiGatewayReties = { maxAttempts?: 1 | 2 | 3 | 4 | 5; retryDelayMs?: number; backoff?: "constant" | "linear" | "exponential"; }; type AiGatewayOptions = { cacheKey?: string; cacheTtl?: number; skipCache?: boolean; metadata?: Record<string, number | string | boolean | null | bigint>; collectLog?: boolean; eventId?: string; requestTimeoutMs?: number; retries?: AiGatewayReties; }; type AiGatewayAPISettings = { gateway: string; accountId: string; apiKey?: string; options?: AiGatewayOptions; }; type AiGatewayBindingSettings = { binding: { run(data: unknown): Promise<Response>; }; options?: AiGatewayOptions; }; type AiGatewaySettings = AiGatewayAPISettings | AiGatewayBindingSettings; declare function createAiGateway(options: AiGatewaySettings): AiGateway; declare function parseAiGatewayOptions(options: AiGatewayOptions): Headers; export { type AiGateway, type AiGatewayAPISettings, type AiGatewayBindingSettings, AiGatewayChatLanguageModel, AiGatewayDoesNotExist, AiGatewayInternalFetchError, type AiGatewayOptions, type AiGatewayReties, type AiGatewaySettings, AiGatewayUnauthorizedError, createAiGateway, parseAiGatewayOptions };