/** * kosha-discovery — OpenAI-compatible model proxy. * * Adds POST /proxy/v1/chat/completions to the Hono server. * The caller sets `model` to one of: * * "claude-opus-4-7" — any canonical model ID or alias * "kosha:cheapest" — cheapest forwardable chat model * "kosha:cheapest[tool_use]" — cheapest with that capability * "kosha:cheapest[128k,vision]" — cheapest with min context + capability * "kosha:cheapest[provider:groq]" — cheapest on a specific provider * * Filters inside brackets are comma-separated and combinable: * any tag in the model card (tool_use, vision, code, …) * k minimum context window in tokens * provider: pin to a specific serving-layer provider * * Supported transports: openai, openai-compatible-http, ollama, anthropic. * Anthropic is proxied through the OpenAI ↔ Anthropic wire translator * (`wire-anthropic.ts`): streaming, tools / tool calls, image_url parts, * response_format, and reasoning_effort are carried; audio input and * non-function tools fail over to a native OpenAI-compatible route. Google, * Bedrock, and Vertex speak cloud-SDK wire formats and are not yet proxied. * * Spend accounting: every successful forward writes a ledger row with the * pre-flight estimate AND, when the upstream returned a `usage` block (JSON * or SSE), the reconciled actual cost. Budget enforcement prefers the actual. * * Response headers added by the proxy: * x-kosha-model — resolved model ID * x-kosha-provider — resolved provider * x-kosha-requested — original model string from the caller * x-kosha-attempt-chain — provider:status for each attempt * x-kosha-estimated-cost-usd — pre-flight estimate * x-kosha-actual-cost-usd — reconciled from upstream usage (non-streaming) * x-kosha-usage-source — upstream | estimate (non-streaming) * x-kosha-wire-notes — Anthropic translator notes (dropped / degraded fields) * @module */ import type { Hono } from "hono"; import type { ModelRegistry } from "./registry.js"; /** In-memory snapshot of proxy hot-path counters for Prometheus `/metrics`. */ export interface ProxyMetricsSnapshot { requestsTotal: number; errorsTotal: number; byProvider: Record; } /** * Snapshot the proxy hot-path counters. In-memory only (resets on restart); * complements the breaker / provider-observation data the registry exposes. */ export declare function snapshotProxyMetrics(): ProxyMetricsSnapshot; /** * Extract a tenant tag from the request. Two carriers are accepted: * * - `x-kosha-tenant: ` — preferred, and the only option when * `KOSHA_PROXY_TOKEN` is set (the Authorization header then carries the * operator token instead). * - `Authorization: Bearer kosha-tenant-` — legacy carrier, kept for * callers that can only set a bearer token. * * The tag is a bucketing label only (per-tenant ledger rows + budget), never * authentication — the bearer is consumed and replaced with the resolved * upstream credential before forwarding. Returns null for any non-conforming * value so downstream code doesn't have to guard for empties. */ export declare function parseTenantTag(authHeader: string | undefined, tenantHeader?: string | undefined): string | null; export declare function registerProxyRoutes(app: Hono, registry: ModelRegistry, shutdownSignal?: AbortSignal): void; //# sourceMappingURL=proxy.d.ts.map