Tyr Admission Controller - v0.36.1
    Preparing search index...

    Type Alias GatewayOptions

    type GatewayOptions = {
        capacityRouting?: CapacityRoutingOptions;
        clientStallTimeoutMs?: number;
        identity?: TyrIdentityOptions;
        idleTimeoutMs?: number;
        isReady?: () => boolean;
        maxOutputTokens?: number;
        maxRequestBodyBytes?: number;
        openaiUpstreamUrl?: string;
        operatorBearerToken?: string;
        pools: PoolConfig[];
        resolveAdmissionClass?: (
            req: IncomingMessage,
            identity: TyrRequestIdentity | undefined,
            pool: string,
        ) => string | undefined | Promise<string | undefined>;
        resolvePriority?: (
            req: IncomingMessage,
            identity?: TyrRequestIdentity,
        ) => LLMPriority | Promise<LLMPriority>;
        responsesState?: ResponsesStateOptions;
        responseTimeoutMs?: number;
        retryHint?: RetryHintOptions;
        shutdownDrainTimeoutMs?: number;
        shutdownStopOnDrainTimeout?: boolean;
        telemetry?: TyrTelemetryOptions;
        trustPriorityHeader?: boolean;
        upstreamUrl?: string;
    }
    Index
    capacityRouting?: CapacityRoutingOptions

    Optional Tyr-to-Tyr capacity-aware request routing.

    clientStallTimeoutMs?: number

    Timeout in milliseconds bounding how long the gateway will wait for a backpressured client to drain before giving up on it. Guards against a client that stops reading entirely (TCP connection stays open, but no drain and no close ever fires) — without this bound, the handler parks in waitForDrain forever, pinning its bulkhead slot and token budget reservation indefinitely. On timeout, the response socket is destroyed, which cascades through close to unwind the handler and release its admission hold. Defaults to idleTimeoutMs when omitted; if both are omitted, a stalled client is never bounded (matching prior behavior).

    Authenticated request identity, role authorization, and role priority.

    idleTimeoutMs?: number

    Timeout in milliseconds for the gap between consecutive chunks of a streaming upstream response body. Guards against a stream that starts fine but then stalls mid-flight (e.g. a hung upstream connection that never sends more data and never closes). The timer resets on every chunk received, so a healthy long-running stream that keeps sending data — no matter how long the overall stream lasts — is never killed by this timeout. Only applies to streaming responses. Omit for no idle timeout.

    isReady?: () => boolean

    Optional process-level readiness gate, such as managed control-plane state.

    maxOutputTokens?: number

    Ceiling for output-limit fields (max_tokens / max_completion_tokens). Requests specifying a value above this are rejected with 400 before admission. This is a sanity bound against malformed/malicious input, not a business policy — actual per-pool output reservation defaults are controlled by PoolConfig.outputCap. Defaults to 200,000.

    maxRequestBodyBytes?: number

    Maximum number of bytes buffered from a request body before it is rejected with 413. Guards against unbounded memory growth from oversized or malicious payloads. Defaults to 1 MiB (1_048_576 bytes).

    openaiUpstreamUrl?: string

    OpenAI-shaped upstream base URL, e.g. "https://api.openai.com". Powers POST /v1/chat/completions and POST /v1/responses. Omit to disable both OpenAI routes.

    operatorBearerToken?: string

    Optional bearer token protecting /stats and /metrics.

    pools: PoolConfig[]
    resolveAdmissionClass?: (
        req: IncomingMessage,
        identity: TyrRequestIdentity | undefined,
        pool: string,
    ) => string | undefined | Promise<string | undefined>

    Override per-pool identity rules with a trusted bounded admission-class ID. Return undefined to use the pool's configured default class.

    resolvePriority?: (
        req: IncomingMessage,
        identity?: TyrRequestIdentity,
    ) => LLMPriority | Promise<LLMPriority>

    Resolve admission priority from an authenticated/trusted request context. This is the preferred way to grant high-priority capacity.

    responsesState?: ResponsesStateOptions

    Opt-in response memory for OpenAI Responses follow-ups.

    With it, Tyr records the provider-reported size of each Responses reply and admits a request that names previous_response_id when it holds a record for that response, reserving the request's own estimate plus the recorded size. A follow-up without a usable record gets 422 unknown_previous_response and the provider is not called. Without this option, previous_response_id is rejected as an invalid request.

    Records are local to this process. Requires openaiUpstreamUrl.

    responseTimeoutMs?: number

    Timeout in milliseconds for the upstream to send response headers (i.e. for the fetch() call to resolve). Covers "upstream never responds at all" — a stalled connection attempt or a hung server that never sends a status line. Cancelled the moment headers arrive; it has no effect on how long a streaming body may subsequently take (see idleTimeoutMs for that). Combined with the client-disconnect abort signal — whichever fires first aborts the upstream call. Omit for no response timeout (client disconnect is still honored).

    retryHint?: RetryHintOptions

    Tuning for the Retry-After hint returned on capacity rejections.

    Tyr estimates the wait from observed upstream completion intervals for the pool. Until it has enough samples it emits no hint rather than a fabricated one. Omit to accept the defaults; set enabled: false to suppress the headers entirely.

    shutdownDrainTimeoutMs?: number

    Maximum graceful-drain wait during shutdown. When the deadline expires, Tyr reports outstanding work and closes remaining HTTP connections. Omit for an unbounded drain, which waits for final token settlement even after a borrowed local slot was returned by deadline abandonment.

    shutdownStopOnDrainTimeout?: boolean

    Stop every request still running when shutdownDrainTimeoutMs elapses. A stopped request that has been sent no part of its reply gets 503 admission_stopped with cause drain_deadline, a reply already under way is cut, and each is counted and audited as stopped. Tyr then closes the remaining connections as before. Requires shutdownDrainTimeoutMs. Default: false, which closes connections without stopping anything.

    Prometheus and structured admission-audit configuration.

    trustPriorityHeader?: boolean

    Trust the raw client-supplied x-priority header. Disabled by default because an unauthenticated caller could otherwise self-assign the reserved high-priority tier. Enable only behind a trusted proxy that strips client copies and injects the header itself.

    upstreamUrl?: string

    Anthropic-shaped upstream base URL, e.g. "https://api.anthropic.com". Powers POST /v1/messages. Omit to disable that route.