File
Blob: types/defines/aig.d.ts
| 1 | type GatewayRetries = { |
| 2 | maxAttempts?: 1 | 2 | 3 | 4 | 5; |
| 3 | retryDelayMs?: number; |
| 4 | backoff?: 'constant' | 'linear' | 'exponential'; |
| 5 | }; |
| 6 | |
| 7 | export type GatewayOptions = { |
| 8 | id: string; |
| 9 | cacheKey?: string; |
| 10 | cacheTtl?: number; |
| 11 | skipCache?: boolean; |
| 12 | metadata?: Record<string, number | string | boolean | null | bigint>; |
| 13 | collectLog?: boolean; |
| 14 | eventId?: string; |
| 15 | requestTimeoutMs?: number; |
| 16 | retries?: GatewayRetries; |
| 17 | }; |
| 18 | |
| 19 | export type UniversalGatewayOptions = Exclude<GatewayOptions, 'id'> & { |
| 20 | /** |
| 21 | ** @deprecated |
| 22 | */ |
| 23 | id?: string; |
| 24 | }; |
| 25 | |
| 26 | export type AiGatewayPatchLog = { |
| 27 | score?: number | null; |
| 28 | feedback?: -1 | 1 | null; |
| 29 | metadata?: Record<string, number | string | boolean | null | bigint> | null; |
| 30 | }; |
| 31 | |
| 32 | export type AiGatewayLog = { |
| 33 | id: string; |
| 34 | provider: string; |
| 35 | model: string; |
| 36 | model_type?: string; |
| 37 | path: string; |
| 38 | duration: number; |
| 39 | request_type?: string; |
| 40 | request_content_type?: string; |
| 41 | status_code: number; |
| 42 | response_content_type?: string; |
| 43 | success: boolean; |
| 44 | cached: boolean; |
| 45 | tokens_in?: number; |
| 46 | tokens_out?: number; |
| 47 | metadata?: Record<string, number | string | boolean | null | bigint>; |
| 48 | step?: number; |
| 49 | cost?: number; |
| 50 | custom_cost?: boolean; |
| 51 | request_size: number; |
| 52 | request_head?: string; |
| 53 | request_head_complete: boolean; |
| 54 | response_size: number; |
| 55 | response_head?: string; |
| 56 | response_head_complete: boolean; |
| 57 | created_at: Date; |
| 58 | }; |
| 59 | |
| 60 | export type AIGatewayProviders = |
| 61 | | 'workers-ai' |
| 62 | | 'anthropic' |
| 63 | | 'aws-bedrock' |
| 64 | | 'azure-openai' |
| 65 | | 'google-vertex-ai' |
| 66 | | 'huggingface' |
| 67 | | 'openai' |
| 68 | | 'perplexity-ai' |
| 69 | | 'replicate' |
| 70 | | 'groq' |
| 71 | | 'cohere' |
| 72 | | 'google-ai-studio' |
| 73 | | 'mistral' |
| 74 | | 'grok' |
| 75 | | 'openrouter' |
| 76 | | 'deepseek' |
| 77 | | 'cerebras' |
| 78 | | 'cartesia' |
| 79 | | 'elevenlabs' |
| 80 | | 'adobe-firefly'; |
| 81 | |
| 82 | export type AIGatewayHeaders = { |
| 83 | 'cf-aig-metadata': |
| 84 | | Record<string, number | string | boolean | null | bigint> |
| 85 | | string; |
| 86 | 'cf-aig-custom-cost': |
| 87 | | { per_token_in?: number; per_token_out?: number } |
| 88 | | { total_cost?: number } |
| 89 | | string; |
| 90 | 'cf-aig-cache-ttl': number | string; |
| 91 | 'cf-aig-skip-cache': boolean | string; |
| 92 | 'cf-aig-cache-key': string; |
| 93 | 'cf-aig-event-id': string; |
| 94 | 'cf-aig-request-timeout': number | string; |
| 95 | 'cf-aig-max-attempts': number | string; |
| 96 | 'cf-aig-retry-delay': number | string; |
| 97 | 'cf-aig-backoff': string; |
| 98 | 'cf-aig-collect-log': boolean | string; |
| 99 | Authorization: string; |
| 100 | 'Content-Type': string; |
| 101 | [key: string]: string | number | boolean | object; |
| 102 | }; |
| 103 | |
| 104 | export type AIGatewayUniversalRequest = { |
| 105 | provider: AIGatewayProviders | string; // eslint-disable-line |
| 106 | endpoint: string; |
| 107 | headers: Partial<AIGatewayHeaders>; |
| 108 | query: unknown; |
| 109 | }; |
| 110 | |
| 111 | export interface AiGatewayInternalError extends Error {} |
| 112 | export interface AiGatewayLogNotFound extends Error {} |
| 113 | |
| 114 | export declare abstract class AiGateway { |
| 115 | patchLog(logId: string, data: AiGatewayPatchLog): Promise<void>; |
| 116 | getLog(logId: string): Promise<AiGatewayLog>; |
| 117 | run( |
| 118 | data: AIGatewayUniversalRequest | AIGatewayUniversalRequest[], |
| 119 | options?: { |
| 120 | gateway?: UniversalGatewayOptions; |
| 121 | extraHeaders?: object; |
| 122 | signal?: AbortSignal; |
| 123 | } |
| 124 | ): Promise<Response>; |
| 125 | getUrl(provider?: AIGatewayProviders | string): Promise<string>; // eslint-disable-line |
| 126 | } |