Nirmos
SDK reference

Gateway types

Public gateway types and declarations exported from @nirmos/sdk.

Import these names from @nirmos/sdk. Optional fields may be absent; nullable fields may be null. Dates in management DTOs remain strings. These declarations do not imply provider support or runtime implementation. Use TypeScript support for indexed DTOs.

The declaration shorthand ExtensibleString<T> means T | (string & {}): known values keep autocomplete while other strings remain assignable. This helper itself is not a root export.

ChatStream

new ChatStream(response: Response): ChatStream
FieldRequiredType
finalResponseYes() => Promise<ChatCompletion>
textYes() => Promise<string>

Usually returned by nirmos.gateway.chat.stream(). Public helpers: finalResponse(): Promise<ChatCompletion>, text(): Promise<string>, and [Symbol.asyncIterator](): AsyncIterator<ChatStreamEvent>. See streaming for consumption rules.

AudioContentPart

export interface AudioContentPart {
    type: "audio";
    data: string;
    format: string;
}

ChatChoice

export interface ChatChoice {
    index: number;
    message: ChatMessage;
    finishReason: FinishReason | null;
}

ChatCompletion

export interface ChatCompletion {
    id: string;
    createdAt: number;
    model: string;
    choices: readonly ChatChoice[];
    outputText: string;
    usage: Usage;
    metadata: RequestMetadata;
}

ChatContentPart

export type ChatContentPart = TextContentPart | ImageContentPart | AudioContentPart;

ChatCreateParams

export type ChatCreateParams = ChatCreateParamsBase & ({
    /** Model identifier. Provider selection is handled by the gateway by default. */
    model: string;
    route?: never;
} | {
    /** Nirmos route identifier. Routing is resolved by the gateway. */
    route: string;
    model?: never;
});

ChatMessage

export interface ChatMessage {
    role: ChatRole;
    content: string | readonly ChatContentPart[];
    name?: string;
    reasoning?: string;
    reasoningDetails?: readonly JsonValue[];
    toolCallId?: string;
    toolCalls?: readonly FunctionToolCall[];
}

ChatRole

export type ChatRole = "system" | "developer" | "user" | "assistant" | "tool";

ChatStreamEvent

export interface ChatStreamEvent {
    type: ExtensibleString<"content.delta" | "toolCall.delta" | "completion.completed">;
    id: string;
    model: string;
    choiceIndex?: number;
    delta?: string;
    toolCall?: Partial<FunctionToolCall>;
    completion?: ChatCompletion;
    metadata: RequestMetadata;
}

Embedding

export type Embedding = {
    index: number;
    values: readonly number[];
    base64?: never;
} | {
    index: number;
    values?: never;
    base64: string;
};

EmbeddingCreateParams

export interface EmbeddingCreateParams {
    /** Model identifier. Provider selection is handled by the gateway by default. */
    model: string;
    input: string | readonly string[];
    dimensions?: number;
    encoding?: "float" | "base64";
    user?: string;
    /** Optional provider override. Omit to use the model's configured default provider. */
    provider?: string;
    /** Options scoped to an upstream provider slug; other targets never receive them. */
    providerOptions?: Readonly<Record<string, Readonly<Record<string, JsonValue>>>>;
    /** @deprecated Embeddings never fall back to another vector space. Requests with this option are rejected. */
    fallbackModels?: readonly string[];
    /** @deprecated Embeddings require direct model selection. */
    routingStrategy?: RoutingStrategy;
}

EmbeddingResponse

export interface EmbeddingResponse {
    model: string;
    embeddings: readonly Embedding[];
    usage: Usage;
    metadata: RequestMetadata;
}

FinishReason

export type FinishReason = ExtensibleString<"stop" | "length" | "toolCalls" | "contentFilter">;

FunctionTool

export interface FunctionTool {
    type: "function";
    function: {
        name: string;
        description?: string;
        parameters?: Readonly<Record<string, unknown>>;
        strict?: boolean;
    };
}

FunctionToolCall

export interface FunctionToolCall {
    id: string;
    type: "function";
    function: {
        name: string;
        arguments: string;
    };
}

GeneratedImage

export interface GeneratedImage {
    assetId?: string;
    expiresAt?: string | null;
    url?: string;
    base64?: string;
    revisedPrompt?: string;
    mediaType?: string;
    width?: number;
    height?: number;
}

ImageContentPart

export interface ImageContentPart {
    type: "image";
    url: string;
    detail?: "auto" | "low" | "high";
}

ImageGenerateParams

export interface ImageGenerateParams {
    storage?: {
        mode: "transient" | "temporary" | "persistent";
        ttlSeconds?: number;
    };
    /** Model identifier. Provider selection is handled by the gateway by default. */
    model: string;
    prompt: string;
    count?: number;
    outputCompression?: number;
    safetyIdentifier?: string;
    moderation?: "auto" | "low";
    size?: ImageSize;
    quality?: ExtensibleString<"standard" | "hd" | "low" | "medium" | "high" | "auto">;
    style?: ExtensibleString<"natural" | "vivid">;
    format?: ExtensibleString<"png" | "jpeg" | "webp">;
    responseFormat?: "url" | "base64";
    background?: ExtensibleString<"transparent" | "opaque" | "auto">;
    user?: string;
    /** Optional provider override. Omit to use the model's configured default provider. */
    provider?: string;
    /** Options scoped to an upstream provider slug; other targets never receive them. */
    providerOptions?: Readonly<Record<string, Readonly<Record<string, JsonValue>>>>;
    metadata?: Readonly<Record<string, JsonValue>>;
}

ImageGeneration

export interface ImageGeneration {
    storage?: {
        mode: "transient" | "temporary" | "persistent";
        expiresAt?: string | null;
    };
    id?: string;
    createdAt: number;
    model: string;
    images: readonly GeneratedImage[];
    usage?: Usage;
    metadata: RequestMetadata;
}

ImageSize

export type ImageSize = ExtensibleString<"1024x1536" | "1536x1024" | "256x256" | "512x512" | "1024x1024" | "1024x1792" | "1792x1024" | "auto">;

PromptReference

export interface PromptReference {
    id: PromptIdentifier;
    version?: number | "active" | "latest";
    variables?: PromptVariableValues;
    cache?: PromptCacheMode;
    /** Prompt messages are inserted before request messages by default. */
    position?: "before" | "after";
}

ResponseFormat

export type ResponseFormat = {
    type: "text";
} | {
    type: "jsonObject";
} | {
    type: "jsonSchema";
    name: string;
    schema: Readonly<Record<string, unknown>>;
    strict?: boolean;
};

RoutingStrategy

export type RoutingStrategy = ExtensibleString<"auto" | "cheapest" | "fastest" | "highestQuality" | "reasoning" | "specific">;

TextContentPart

export interface TextContentPart {
    type: "text";
    text: string;
}

ToolChoice

export type ToolChoice = "auto" | "none" | "required" | {
    type: "function";
    function: {
        name: string;
    };
};

ImageRequest

export type ImageRequest = {
    storage?: {
        mode: "transient" | "temporary" | "persistent";
        ttlSeconds?: number;
    };
    model: string;
    prompt: string;
    n?: number | null;
    size?: string | null;
    quality?: string | null;
    aspect_ratio?: string | null;
    resolution?: string | null;
    background?: "auto" | "opaque" | "transparent" | null;
    output_format?: "png" | "jpeg" | "webp" | null;
    output_compression?: number | null;
    moderation?: "auto" | "low" | null;
    safety_identifier?: string | null;
    user?: string;
    response_format?: "b64_json" | "url" | null;
    stream?: false | null;
    provider?: string;
    metadata?: {
        [key: string]: ImageRequest___schema0;
    };
};

ImageCapabilities

// Generated from browser-safe image contracts. Do not edit.
export type ImageCapabilities = {
    text_to_image: boolean;
    image_edit: boolean;
    reference_images: boolean;
    transparent_background: boolean;
    supported_sizes: Array<string>;
    supported_output_formats: Array<"png" | "jpeg" | "webp">;
    supported_quality_levels: Array<string>;
    supports_multiple_outputs: boolean;
    max_outputs: number;
    supports_streaming: boolean;
    supports_seed: boolean;
    supports_negative_prompt: boolean;
    supports_moderation_controls: boolean;
    async_only: boolean;
    custom_sizes?: boolean;
    supported_aspect_ratios?: Array<string>;
    supported_resolutions?: Array<string>;
    default_output_format?: "png" | "jpeg" | "webp";
    supports_output_format?: boolean;
    max_prompt_length?: number;
};

ImageUsage

export type ImageUsage = {
    input_tokens: number;
    output_tokens: number;
    total_tokens: number;
    input_tokens_details?: {
        text_tokens: number;
        image_tokens: number;
    };
    output_tokens_details?: {
        text_tokens: number;
        image_tokens: number;
    };
};

ImagesResponse

export type ImagesResponse = {
    storage?: {
        mode: "transient" | "temporary" | "persistent";
        expiresAt?: string | null;
    };
    created: number;
    data: Array<{
        asset_id?: string;
        expires_at?: string | null;
        b64_json?: string;
        url?: string;
        revised_prompt?: string;
        media_type?: "image/png" | "image/jpeg" | "image/webp";
    }>;
    usage?: {
        input_tokens: number;
        output_tokens: number;
        total_tokens: number;
        input_tokens_details?: {
            text_tokens: number;
            image_tokens: number;
        };
        output_tokens_details?: {
            text_tokens: number;
            image_tokens: number;
        };
    };
    background?: "opaque" | "transparent";
    output_format?: "png" | "jpeg" | "webp";
    quality?: string;
    size?: string;
    safety_identifier?: string | null;
};

ImageModel

export type ImageModel = {
    id: string;
    object: "model";
    owned_by: string;
    capabilities: {
        text_to_image: boolean;
        image_edit: boolean;
        reference_images: boolean;
        transparent_background: boolean;
        supported_sizes: Array<string>;
        supported_output_formats: Array<"png" | "jpeg" | "webp">;
        supported_quality_levels: Array<string>;
        supports_multiple_outputs: boolean;
        max_outputs: number;
        supports_streaming: boolean;
        supports_seed: boolean;
        supports_negative_prompt: boolean;
        supports_moderation_controls: boolean;
        async_only: boolean;
        custom_sizes?: boolean;
        supported_aspect_ratios?: Array<string>;
        supported_resolutions?: Array<string>;
        default_output_format?: "png" | "jpeg" | "webp";
        supports_output_format?: boolean;
        max_prompt_length?: number;
    };
};

ImageModels

export type ImageModels = {
    object: "list";
    data: Array<{
        id: string;
        object: "model";
        owned_by: string;
        capabilities: {
            text_to_image: boolean;
            image_edit: boolean;
            reference_images: boolean;
            transparent_background: boolean;
            supported_sizes: Array<string>;
            supported_output_formats: Array<"png" | "jpeg" | "webp">;
            supported_quality_levels: Array<string>;
            supports_multiple_outputs: boolean;
            max_outputs: number;
            supports_streaming: boolean;
            supports_seed: boolean;
            supports_negative_prompt: boolean;
            supports_moderation_controls: boolean;
            async_only: boolean;
            custom_sizes?: boolean;
            supported_aspect_ratios?: Array<string>;
            supported_resolutions?: Array<string>;
            default_output_format?: "png" | "jpeg" | "webp";
            supports_output_format?: boolean;
            max_prompt_length?: number;
        };
    }>;
};

ImageResult

export type ImageResult = ImagesResponse & {
    readonly generationId?: string;
    readonly requestId?: string;
};

On this page