export interface ErrorResponse { error: string; message: string; details?: any; } export type Role = 'system' | 'user' | 'assistant' | 'tool' | 'function' | 'model' | 'developer'; export type ImageDetail = 'auto' | 'low' | 'high'; export type ImageSize = '256x256' | '512x512' | '1024x1024' | '1792x1024' | '1024x1792' | '1536x1024' | '1024x1536'; export type ImageQuality = 'standard' | 'hd'; export type ImageStyle = 'vivid' | 'natural'; export type AudioFormat = 'mp3' | 'opus' | 'aac' | 'flac' | 'wav' | 'pcm'; export type VideoSize = '720x1280' | '1280x720' | '1024x1792' | '1792x1024'; export type AudioMimeType = 'audio/mpeg' | 'audio/mp4' | 'audio/wav' | 'audio/webm' | 'audio/ogg' | 'audio/flac'; export type ImageMimeType = 'image/jpeg' | 'image/png' | 'image/gif' | 'image/webp'; export type ToolChoice = 'auto' | 'required' | 'none' | { type: 'function'; function: { name: string; }; }; export type FinishReason = 'completed' | 'length_limit' | 'tool_call' | 'filtered' | 'error'; export type ResponseFormatType = 'text' | 'json_object' | 'json_schema'; export type EncodingFormat = 'float' | 'base64'; export declare const ADAPTER_HANDLED = "__ADAPTER_HANDLED__"; type BaseRequest = { /** * Gate identifier. Use gate ID. * * @example * gate: "123e4567-e89b-12d3-a456-426614174000" */ gateId: string; /** Server-internal: the gate's pinned BYOK key, stamped by request * routing from gate config. Never set by callers. */ pinnedProviderKeyId?: string; gateName?: string; model?: string; metadata?: Record; /** * Stable identifier for the end-user this request is for. When an active * experiment on this gate is configured with `randomization_unit = 'user'`, * requests with the same `endUserId` always land in the same variant. * Requests without it are excluded from user-unit experiments. * * Use whatever stable string makes sense for your product — an end-user ID, * a session token, a device fingerprint. Not PII-sensitive on our side; * hashed for assignment and never exposed back externally. */ endUserId?: string; }; /** * Task type determines how request data is interpreted. * When omitted, defaults to the gate's configured taskType. */ export type TaskType = 'chat' | 'image' | 'video' | 'embeddings' | 'tts' | 'ocr'; /** * Internal VerlonRequest type with required type field (used by API after type resolution) */ export type VerlonRequest = (BaseRequest & { type: 'chat'; data: ChatRequest; }) | (BaseRequest & { type: 'image'; data: ImageGenerationRequest; }) | (BaseRequest & { type: 'video'; data: VideoGenerationRequest; }) | (BaseRequest & { type: 'embeddings'; data: EmbeddingsRequest; }) | (BaseRequest & { type: 'tts'; data: TextToSpeechRequest; }) | (BaseRequest & { type: 'ocr'; data: OCRRequest; }); /** * User-facing VerlonRequest type with optional type field. * Type defaults to gate's taskType when omitted, but can be overridden. */ export type VerlonRequestInput = (BaseRequest & { type?: 'chat'; data: ChatRequest; }) | (BaseRequest & { type?: 'image'; data: ImageGenerationRequest; }) | (BaseRequest & { type?: 'video'; data: VideoGenerationRequest; }) | (BaseRequest & { type?: 'embeddings'; data: EmbeddingsRequest; }) | (BaseRequest & { type?: 'tts'; data: TextToSpeechRequest; }) | (BaseRequest & { type?: 'ocr'; data: OCRRequest; }); /** * A single value bound to a template variable. Recursive so callers * can pass nested objects and walk them from the template via * dot-path placeholders. * * Coercion at render time: * - `string` → as-is * - `number` / `boolean` → `String(v)` (`"5"`, `"true"`) * - `null` / `undefined` → `""` (empty string) * - `Array` → elements joined with `", "` (each element coerced * first); arrays of objects are coerced as JSON per-element * - `object` → `JSON.stringify(value)` when referenced bare * (e.g. `{{customer}}` with `vars: { customer: { name: 'Alice' } }` * renders as `'{"name":"Alice"}'`). Use dot-paths * (`{{customer.name}}`) for human-readable templates. */ export type TemplateVarValue = string | number | boolean | null | undefined | TemplateVarValue[] | { [key: string]: TemplateVarValue; }; /** * Caller-supplied values for `{{var}}` and `{{user.field}}` * placeholders in a gate's stored `system_prompt`. Pass nested * objects when the template uses dot-paths * (`{{customer.name}}` → `vars: { customer: { name: 'Alice' } }`), * or flat keys when it doesn't (`{{name}}` → `vars: { name: 'Alice' }`). * * If the gate's prompt declares variables and `vars` is missing one * (and that variable has no `{{var | default}}`), the API responds * with `400 MISSING_TEMPLATE_VARS`, which the SDK surfaces as * `VerlonTemplateError` with a populated `missingVars` array. * For dot-paths, the full path appears in `missingVars` (e.g. * `["customer.email"]`, not `["customer"]`). */ export type TemplateVars = Record; export interface ChatRequest { messages: MultimodalMessage[]; systemPrompt?: string; /** * Values for `{{var}}` / `{{var | default}}` placeholders in the * gate's stored `system_prompt`. Optional — gates without templated * prompts ignore this field; templates with all-optional variables * accept an empty object or no `vars` at all. */ vars?: TemplateVars; tools?: Tool[]; toolChoice?: ToolChoice; temperature?: number; maxTokens?: number; topP?: number; /** * Anthropic + Google support `top_k` natively; OpenAI / Mistral * ignore. When omitted, the gate's stored `topK` (or provider * default) is used. */ topK?: number; stream?: boolean; stopSequences?: string[]; frequencyPenalty?: number; presencePenalty?: number; responseFormat?: ResponseFormatType | { type: ResponseFormatType; json_schema?: unknown; }; seed?: number; /** * Canonical reasoning-effort knob. Adapters translate to each * provider's native shape. See `models.ts` `GateBase.reasoningEffort` * for the full mapping. */ reasoningEffort?: 'low' | 'medium' | 'high'; /** * REQUESTED service tier, forwarded to providers that accept one * (OpenAI: auto | default | flex | priority). The provider may serve a * different tier under load and reports the one it used; billing always * follows the REPORTED tier (`VerlonResponse.serviceTier`), and a * requested/served mismatch is logged. Providers with no tier concept * ignore this. */ serviceTier?: string; /** * Region-pinned inference (Anthropic: `inference_geo`, "us" | "global"; * Claude 4.6+). Pinning to a region is a hard constraint the provider * honors or fails, and it carries a published premium (US-only: 1.1x on * every token category, stacking with tier discounts) — billing applies * the model's stored residency multiplier when a request pins. */ inferenceGeo?: string; /** * Ask the provider to reuse cached prompt prefixes. Set by the * Anthropic drop-in route when the caller marks its prompt with * `cache_control`. The Anthropic adapter injects breakpoints at the * canonical positions (system prompt, last message); providers with * automatic prefix caching (OpenAI, Google) ignore this — they cache * regardless. */ promptCache?: boolean; /** * Mistral-only guardrail toggle: asks Mistral to prepend its safety * prompt to the conversation. Forwarded verbatim by the Mistral * adapter; every other provider ignores it. Carried in the normalized * request so the drop-in dialect (`safe_prompt`) survives conversion * instead of being silently dropped. */ safePrompt?: boolean; /** * Fill-in-the-middle suffix (code after the cursor). Presence — even * as an empty string — marks the request as FIM: the Mistral adapter * routes it to the dedicated /v1/fim endpoint (Codestral) with the * message content as the prompt. Providers without a FIM endpoint * ignore it and complete the prompt alone. */ fimSuffix?: string; /** * Wire protocol the request originated from. `'responses'` routes the * OpenAI adapter through `client.responses.create` instead of chat * completions, using the verbatim `responsesInput` carrier below. * Defaults to chat completions when omitted. OpenAI-only. */ wireApi?: 'chat' | 'responses'; /** * Verbatim OpenAI Responses `input` items (message / function_call / * function_call_output / reasoning). Preserved untouched so encrypted * reasoning content and item ordering survive multi-turn tool loops — * the normalized `messages` above are derived for logging only. Typed * loosely here to avoid a hard SDK type dependency in the core request. */ responsesInput?: unknown[]; /** Responses API server-side state — rejected in v1 (stateless). */ store?: boolean; previousResponseId?: string; /** Responses API `include` (e.g. ['reasoning.encrypted_content']). */ include?: string[]; parallelToolCalls?: boolean; /** * Provider-executed tools the caller requested, normalized. Populated * by the Anthropic drop-in route when it strips a typed server tool * (e.g. `web_search_20250305`) from the function-tool list: the * request's INTENT survives here so an adapter whose provider offers * the same hosted capability can serve it (Meta's search grounding * takes `{type:"web_search"}` on its Responses wire). Adapters with no * equivalent ignore the field — the request degrades to a plain * completion, exactly as before this carrier existed. */ serverTools?: Array<{ type: 'web_search'; /** Anthropic `allowed_domains`; Responses `filters.allowed_domains`. */ allowedDomains?: string[]; /** Anthropic-only — no Responses equivalent; adapters drop it. */ blockedDomains?: string[]; /** Anthropic-only cap; no Responses equivalent. */ maxUses?: number; userLocation?: { city?: string; country?: string; region?: string; timezone?: string; }; }>; /** * Verbatim Anthropic Messages `tools` array, set by the Anthropic * drop-in route when the request uses tool search (a * `tool_search_tool_*` server tool and/or `defer_loading` markers). * The Anthropic adapter forwards it untouched so deferred loading * survives the gateway; the normalized `tools` above are derived for * logging and for non-Anthropic providers, which load every tool — * tool search degrades gracefully cross-provider. Anthropic-only. */ anthropicTools?: unknown[]; /** * Verbatim Anthropic Messages `messages` array, carried alongside * `anthropicTools` so `server_tool_use` / `tool_search_tool_result` * history blocks (and the caller's own `cache_control` positions) * survive multi-turn replay. The normalized `messages` above are * derived for logging only when this is present. Anthropic-only. */ anthropicMessages?: unknown[]; /** * Verbatim `anthropic-beta` header value from an Anthropic drop-in * caller. Forwarded unchanged by the Anthropic adapter, never * allowlisted: the set of capability values changes with every * client release, and a gateway pinned to the values it knows today * silently disables the next one. Capabilities that add body fields * pair them with a header value, so stripping it while forwarding * the body is what turns a quiet no-op into a 400. Anthropic-only — * other providers have no equivalent. */ anthropicBeta?: string; } export interface MultimodalMessage { role: Role; content?: string; images?: ImageInput[]; audio?: AudioInput; toolCallId?: string; toolCalls?: ToolCall[]; name?: string; } export interface ImageInput { url?: string; base64?: string; mimeType?: ImageMimeType; detail?: ImageDetail; } export interface AudioInput { url?: string; base64?: string; mimeType?: AudioMimeType; format?: AudioFormat; } export interface Tool { type: 'function'; function: { name: string; description?: string; parameters?: { type: 'object' | 'string' | 'number' | 'boolean' | 'array'; properties?: Record; required?: string[]; }; }; } export interface ToolCall { id: string; type: 'function'; function: { name: string; arguments: string; }; /** * Provider-specific, non-portable passthrough. Only the adapter that * produced a tool call reads its own metadata back; other providers * ignore it. Currently carries Gemini's `thoughtSignature`, which must * be echoed on the follow-up turn or Gemini 3.x rejects the tool * round-trip with a 400. */ providerMetadata?: { thoughtSignature?: string; }; } export interface ImageGenerationRequest { prompt: string; size?: ImageSize; quality?: ImageQuality; count?: number; style?: ImageStyle; seed?: number; } export type VideoReferenceType = 'subject' | 'style' | 'asset'; export interface VideoReferenceImage { url?: string; base64?: string; referenceType?: VideoReferenceType; } export interface VideoImageInput { url?: string; base64?: string; } export interface VideoGenerationRequest { prompt: string; duration?: number | string; size?: VideoSize; fps?: number; seed?: number; negativePrompt?: string; numberOfVideos?: number; personGeneration?: string; image?: VideoImageInput; lastFrame?: VideoImageInput; referenceImages?: VideoReferenceImage[]; } export interface EmbeddingsRequest { input: string | string[]; dimensions?: number; encodingFormat?: EncodingFormat; } export interface TextToSpeechRequest { input: string; voice?: string; speed?: number; responseFormat?: AudioFormat; } export type OCRDocumentType = 'document_url' | 'image_url' | 'base64'; export type OCRTableFormat = 'markdown' | 'html'; export interface OCRRequest { documentUrl?: string; imageUrl?: string; base64?: string; mimeType?: string; tableFormat?: OCRTableFormat; includeImageBase64?: boolean; extractHeader?: boolean; extractFooter?: boolean; } export interface OCRPage { index: number; markdown: string; images?: Array<{ id: string; base64?: string; topLeftX?: number; topLeftY?: number; bottomRightX?: number; bottomRightY?: number; }>; tables?: Array<{ id: string; html?: string; }>; hyperlinks?: Array<{ text: string; url: string; }>; header?: string | null; footer?: string | null; dimensions?: { width: number; height: number; dpi?: number; }; } export interface OCROutput { pages: OCRPage[]; model: string; documentAnnotation?: Record | null; usageInfo?: { pagesProcessed?: number; docSizeBytes?: number; }; } /** Provenance of a response's `cost` value. */ export type CostSource = 'provider_reported' | 'computed' | 'estimated' | 'unpriced' | 'partial'; export interface VerlonResponse { id?: string; created?: number; content?: string; images?: ImageOutput[]; videos?: VideoOutput[]; audio?: AudioOutput; embeddings?: number[][]; ocr?: OCROutput; toolCalls?: ToolCall[]; model?: string; finishReason?: FinishReason; rawFinishReason?: string; usage?: { promptTokens?: number; completionTokens?: number; totalTokens?: number; /** Prompt tokens the provider served from its prompt cache (a * subset of promptTokens). Cached tokens are billed at the model's * cached-input rate when the registry declares one. */ cachedPromptTokens?: number; /** Hidden reasoning tokens (a subset of completionTokens — billing * treats reasoning as output). Lets provider-faithful wires * reconstruct the visible/reasoning split (e.g. Gemini's * candidatesTokenCount vs thoughtsTokenCount). */ reasoningTokens?: number; }; stream?: boolean; cost?: number; /** How `cost` was produced. `provider_reported` = the provider's own * billed amount (wins over our math); `computed` = registry price x * provider-reported usage; `estimated` = computed from incomplete * inputs (e.g. an unmatched resolution tier billed at the highest * published tier); `unpriced` = the model had no usable registry * pricing and cost is 0 AND wrong; `partial` = the stream died and * cost covers only the usage observed before the failure. */ costSource?: CostSource; /** Service tier the provider reported billing this response at * (normalized lowercase; OpenAI's `default` -> `standard`). Absent when * the provider reported none. The REPORTED tier, not the requested one — * providers fall back under load and invoice at the tier they served. */ serviceTier?: string; latencyMs?: number; usedPlatformKey?: boolean; /** Platform pool key that actually served this response (stamped per * attempt). Absent for BYOK and the env break-glass fallback. */ platformKeyId?: string; /** BYOK key that actually served this response (stamped per attempt). * Absent for platform-served traffic. */ providerKeyId?: string; raw?: unknown; /** OpenAI Responses API: the provider response id (for `previous_response_id`). */ responseId?: string; /** Provider-faithful streaming (OpenAI Responses, Anthropic tool * search): the raw SSE event to re-serialize verbatim. */ rawEvent?: unknown; /** * Incremental tool-call fragments during streaming, in the shape * drop-in wires expect: the first fragment of a call carries `id` * and `function.name`, later ones only append `function.arguments`. * * Separate from `toolCalls` on purpose. `toolCalls` keeps its * meaning — the complete, parseable calls on the terminal chunk, * which request logging and cost attribution read — while these * carry the progressive detail a client needs to render a large * tool input as it is generated rather than in one lump at the end. */ toolCallDeltas?: Array<{ index?: number; id?: string; type?: 'function'; function?: { name?: string; arguments?: string; }; }>; /** * Web citations attached to `content` by a provider-executed search * (Meta search grounding's `url_citation` annotations). Indexes are * character offsets into `content`, so `cited_text` is recoverable as * `content.slice(startIndex, endIndex)` by whichever wire needs it. */ citations?: Array<{ url: string; title?: string | null; startIndex: number; endIndex: number; }>; } export interface ImageOutput { url?: string; base64?: string; revisedPrompt?: string; } export interface VideoOutput { url?: string; base64?: string; duration?: number; revisedPrompt?: string; } export interface AudioOutput { url?: string; base64?: string; format?: AudioFormat; text?: string; duration?: number; } export {}; //# sourceMappingURL=api-v3.d.ts.map