Interface CompletionGateway

interface CompletionGateway {
    resolve(route, after?, failure?): Promise<null | CompletionResolution>;
    stream(resolution, messages, options, responseSchema?, schemaName?, schemaInPrompt?, onLateUsage?): CompletionAttempt;
    schemaInstruction?(resolution, responseSchema, schemaName?): undefined | string;
}

Methods

  • The route's first hop that can start, or, given the hop that failed, the next one. failure is the error that hop failed with: the walk reads it as generateText's and streamText's walks do (a refusal passes over the policy chain's Claude legs; a standing uncensored leg that failed on availability is owed the next ranked model). Without it the hop counts as an availability failure.

    Parameters

    Returns Promise<null | CompletionResolution>

  • Parameters

    • resolution: CompletionResolution
    • messages: ChatMessage[]
    • options: ModelCompletionOptions
    • Optional responseSchema: ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>
    • Optional schemaName: string
    • Optional schemaInPrompt: boolean

      True when messages already carry the schema's instructions (a structured reply puts its own in the system prompt): a hop whose payload carries no schema then gets no second copy.

    • Optional onLateUsage: ((report) => void)

      Receives the usage the provider reports for this attempt after the caller's signal ended it (LateAttemptUsage), once the stream left running has ended. Without a listener, or when it throws, that usage is logged at warn level with its token counts.

    Returns CompletionAttempt

  • The schema instructions, in generateObject's words, that a hop's system prompt needs for responseSchema: the text when the hop's provider payload carries no schema (no payload for the provider or model, or a JSON mode without one), undefined when the payload carries it. A caller that puts the text in its prompt itself passes schemaInPrompt to stream().

    Parameters

    • resolution: CompletionResolution
    • responseSchema: ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>
    • Optional schemaName: string

    Returns undefined | string