/** * The `irp-suggest` routing protocol: Inference Routing Protocol (IRP) suggest-only mode, * https://github.com/inference-routing/spec/blob/main/SPEC.md * It is one routing protocol among others (see `./routing.ts`), not a default. * Requests are plain IRP paths and bodies. IRP paths name no service, so a seller offers at * most one `irp-suggest` service and the path alone identifies the service being bought. */ import type { RoutingWireProtocol } from './routing.js'; /** Service API protocol advertised by sellers that rank destinations over IRP suggest-only mode. */ export declare const IRP_SUGGEST_PROTOCOL = "irp-suggest"; /** IRP §4: the router's supported models (free on AntSeed). */ export declare const IRP_MODELS_PATH = "/v1/routing/models"; /** `GET /v1/routing/models` entry meaning the router scores any model the buyer sends. */ export declare const IRP_ANY_MODEL = "*"; /** IRP §5: suggest-only ranking (one completed request on AntSeed). */ export declare const IRP_RANK_PATH = "/v1/routing/rank"; export declare const IRP_RANKING_OBJECT = "routing.ranking"; export declare const IRP_MAX_CANDIDATES = 512; export declare const IRP_MAX_CANDIDATE_ID_LENGTH = 128; /** IRP default when `cost_quality_tradeoff` is absent. */ export declare const IRP_DEFAULT_COST_QUALITY_TRADEOFF = 5; /** USD per 1M tokens, as on a candidate. */ export type IrpPricing = { input: number; cache_read: number; output: number; }; /** * A `GET /v1/routing/models` entry. AntSeed extension: on the `*` entry, `max_pricing` caps * the candidates the buyer sends through it; an omitted field means no limit. */ export type IrpModelEntry = { id: string; max_pricing?: Partial; }; /** IRP §4 `GET /v1/routing/models` response. */ export type IrpModelsResponse = { object: 'list'; data: Array; }; /** IRP §3.2 candidate. */ export type IrpCandidate = { id: string; model: string; /** USD per 1M tokens. */ pricing: IrpPricing; /** Absent means 0 cache reads. */ expected_usage?: { cache_read_tokens?: number; }; }; /** * The inference request being ranked, as an OpenAI Chat Completions body (IRP `request`). * Routers ignore `model` and `stream`; they never forward it. */ export type IrpInferenceRequest = { messages: Array<{ role: string; [key: string]: unknown; }>; [key: string]: unknown; }; /** IRP §5.1 `POST /v1/routing/rank`. */ export type IrpRankRequest = { request: IrpInferenceRequest; routing: { /** 0 = best quality regardless of price, 10 = cheapest acceptable. Default 5. */ cost_quality_tradeoff?: number; candidates: IrpCandidate[]; }; }; /** IRP §3.4 ranked entry. Only `candidate_id` is required. */ export type IrpRankedEntry = { candidate_id: string; expected_quality?: number; expected_cost_usd?: number; expected_usage?: { input_tokens: number; cache_read_tokens: number; output_tokens: number; }; reasoning_effort?: string; }; /** IRP §5.2 response. */ export type IrpRankResponse = { id: string; object: typeof IRP_RANKING_OBJECT; created: number; router: { id: string; version: string; }; ranked: IrpRankedEntry[]; }; /** IRP §8 problem types. */ export declare const IRP_PROBLEM_TYPES: { readonly invalidRequest: "urn:irp:problem:invalid-request"; readonly paymentRequired: "urn:irp:problem:payment-required"; readonly noScorableCandidate: "urn:irp:problem:no-scorable-candidate"; readonly unavailable: "urn:irp:problem:unavailable"; }; export type IrpProblem = { type?: string; title?: string; status?: number; detail?: string; }; /** An IRP `cost_quality_tradeoff`: an integer 0-10. */ export declare function isCostQualityTradeoff(value: unknown): value is number; /** Whether `path` (query string ignored) is an IRP routing endpoint. */ export declare function isIrpPath(path: string): boolean; /** Validate `GET /v1/routing/models` and return the model IDs. Unknown members are ignored (IRP §2). */ export declare function parseIrpModelsResponse(value: unknown): string[]; /** * Validate `GET /v1/routing/models` and return its entries, keeping `max_pricing` where a * router sets it. Unknown members are ignored (IRP §2). */ export declare function parseIrpModelEntries(value: unknown): IrpModelEntry[]; /** Whether `pricing` is within `limit`; an omitted limit field allows any price. */ export declare function withinIrpPricing(pricing: IrpPricing, limit: Partial | undefined): boolean; /** * Check a rank request. Buyers call it before paying so malformed requests never leave the * device; routers can call it before ranking. With `supportedModels`, every candidate must * use a listed model. Unknown members are ignored (IRP §2). */ export declare function validateIrpRankRequest(value: unknown, supportedModels?: readonly string[]): asserts value is IrpRankRequest; /** * Validate an IRP ranking and keep entries naming a sent candidate, in the router's order * (IRP §5.3: clients reject unknown `candidate_id`s). Duplicates and malformed entries are * dropped; optional predictions are kept only when well-formed. * Throws when the envelope is invalid or no entry survives. */ export declare function validateIrpRankResponse(value: unknown, candidates: readonly Pick[]): IrpRankedEntry[]; /** IRP §8 Problem Details (RFC 9457), when the body is one. */ export declare function parseIrpProblem(body: unknown): IrpProblem | null; /** A serialized IRP problem response body (`application/problem+json`). */ export declare function irpProblemBody(status: number, type: string, title: string, detail?: string): Uint8Array; /** * What the node and unit billing need from `irp-suggest`: `GET /v1/routing/models` is the free * catalog, `POST /v1/routing/rank` the billed ranking, and a ranking is billable when it is a * valid IRP ranking naming at least one candidate the request sent. */ export declare const IRP_SUGGEST_WIRE: RoutingWireProtocol; //# sourceMappingURL=irp.d.ts.map