Interface CompletionRoute

What a turn asks the gateway for. Unset fields take the gateway's defaults.

interface CompletionRoute {
    modelId?: string;
    providerId?: string;
    messages: ChatMessage[];
    tools?: ITool<any, any>[] | Record<string, unknown>[];
    router?: IModelRouter;
    routerParams?: Partial<ModelRouteParams>;
    hostPolicy?: HostLLMPolicy;
    policyTier?: "safe" | "standard" | "mature" | "private-adult";
    fallbackProviders?: FallbackProviderEntry[];
    apiKey?: string;
    baseUrl?: string;
    callOptions?: Pick<GenerateTextOptions, "maxTokens" | "effort" | "cache">;
    onFallback?: ((info) => void);
    onHopFailure?: ((info) => void);
    onHopSkipped?: ((info) => void);
}

Properties

modelId?: string
providerId?: string
messages: ChatMessage[]

The turn's messages so far; the last user message is the router's task hint.

tools?: ITool<any, any>[] | Record<string, unknown>[]
router?: IModelRouter
routerParams?: Partial<ModelRouteParams>
hostPolicy?: HostLLMPolicy
policyTier?: "safe" | "standard" | "mature" | "private-adult"
fallbackProviders?: FallbackProviderEntry[]

Caller chain. Undefined builds the policy-aware chain from the environment; an empty array disables fallback. Either is resolved once, as generateText's walk resolves its chain: entries naming an excluded model or lacking an explicitly required capability are passed over, and so is the policy chain's entry for the first model.

apiKey?: string

Credentials for the primary only; fallback hops read the environment, as streamText's walk does. Set in the gateway defaults beside a provider or model, they are for that provider: a turn that names another provider does not take them.

baseUrl?: string
callOptions?: Pick<GenerateTextOptions, "maxTokens" | "effort" | "cache">

The call's own effort, cache and output budget, from which each fallback hop's overrides are derived.

onFallback?: ((info) => void)

Called when the turn moves to a hop after the primary.

Type declaration

    • (info): void
    • Parameters

      • info: {
            from: string;
            to: string;
            hop: number;
            error: Error;
        }
        • from: string
        • to: string
        • hop: number
        • error: Error

      Returns void

onHopFailure?: ((info) => void)

Called for every hop that could not start (initialisation failure or open circuit).

Type declaration

    • (info): void
    • Parameters

      • info: {
            providerId: string;
            hop: number;
            error: Error;
        }
        • providerId: string
        • hop: number
        • error: Error

      Returns void

onHopSkipped?: ((info) => void)

Called for every chain entry the walk passes over without an attempt: an excluded model, a missing required capability, the policy chain's entry for the first model, a refill no standing leg is owed, a Claude leg after a refusal.

Type declaration

    • (info): void
    • Parameters

      • info: CompletionHopSkip

      Returns void