import type { CredentialResolver } from '../types/lifecycle.js'; /** The part of a `fetch` response the server helpers read. */ export interface OpenAIRealtimeServerFetchResponse { /** True for a 2xx status. */ readonly ok: boolean; /** HTTP status code. */ readonly status: number; /** HTTP status text. */ readonly statusText?: string; /** Reads the body as text. */ text(): Promise; /** Reads the body as JSON. */ json?(): Promise; } /** The part of `fetch` the server helpers use. */ export type OpenAIRealtimeServerFetch = (input: string, init: { method: string; headers?: Record; body?: unknown; signal?: AbortSignal; }) => Promise; /** The part of `FormData` the SDP exchange needs. */ export interface FormDataLike { /** Sets a field. */ set(name: string, value: string): void; } /** Server-side options for creating OpenAI realtime sessions, where the API key lives. */ export interface OpenAIRealtimeServerOptions { /** OpenAI API key. Never send it to a browser. Optional when `credentials` resolves one for the tenant. */ apiKey?: string; /** * Resolves the key per tenant, as the client's `lifecycle.credentials` does, such as * `tenantCredentials()`: the tenant's key replaces `apiKey` in the session or the secret minted for * it, so a browser's token is minted with its tenant's key. A resolver that throws refuses it. */ credentials?: CredentialResolver; /** The tenant the session or the secret is for, whose key `credentials` resolves. */ tenantId?: string; /** The provider's name, as `credentials` reads it. Defaults to `openai`. */ provider?: string; /** Realtime model. */ model: string; /** Session settings sent to OpenAI, such as instructions or voice. */ session?: Record; /** API base URL. Defaults to `https://api.openai.com/v1`. */ baseUrl?: string; /** Identifies the end user to OpenAI's safety systems, sent as `OpenAI-Safety-Identifier`. */ safetyIdentifier?: string; /** Replaces the global `fetch`. */ fetch?: OpenAIRealtimeServerFetch; /** Creates the multipart form, for runtimes without a global `FormData`. */ formDataFactory?: () => FormDataLike; } /** A short-lived client secret a browser can connect with. */ export interface OpenAIRealtimeClientSecret { /** The token. */ value: string; /** Epoch seconds when it expires. */ expiresAt?: number; /** OpenAI's response, unmodified. */ raw: Record; } /** * Exchanges a browser's SDP offer with OpenAI and returns the SDP answer. What your * `sessionEndpoint` does in `unified-sdp` mode. */ export declare function createOpenAIRealtimeCall(sdp: string, options: OpenAIRealtimeServerOptions, signal?: AbortSignal): Promise; /** * Mints an ephemeral client secret for a browser session. What your `sessionEndpoint` does in * `ephemeral-token` mode. */ export declare function createOpenAIRealtimeClientSecret(options: OpenAIRealtimeServerOptions, signal?: AbortSignal): Promise; /** What controlling a call OpenAI carries needs: the key, and how to reach OpenAI. */ export type OpenAIRealtimeCallOptions = Pick; /** * Answers a call OpenAI is carrying, such as an incoming SIP call, with the session that will run * it: its model, instructions, tools, and audio, as `createOpenAISessionUpdate()` builds them. */ export declare function acceptOpenAIRealtimeCall(callId: string, session: Record, options: OpenAIRealtimeCallOptions, signal?: AbortSignal): Promise; /** Declines a call, with a SIP status: 603 (decline) by default, or 486 (busy), say. */ export declare function rejectOpenAIRealtimeCall(callId: string, options: OpenAIRealtimeCallOptions & { statusCode?: number; }, signal?: AbortSignal): Promise; /** Transfers an accepted call to another number or SIP address, such as `tel:+14155550123`. */ export declare function referOpenAIRealtimeCall(callId: string, targetUri: string, options: OpenAIRealtimeCallOptions, signal?: AbortSignal): Promise; /** Ends a call. */ export declare function hangupOpenAIRealtimeCall(callId: string, options: OpenAIRealtimeCallOptions, signal?: AbortSignal): Promise; /** Headers as a `Headers` object or a plain record, such as Node's `request.headers`. */ export type OpenAIWebhookHeaders = { get(name: string): string | null; } | Record; /** One event OpenAI delivered to your webhook. */ export interface OpenAIWebhookEvent { /** The event's id. */ id: string; /** What happened, such as `realtime.call.incoming`. */ type: string; /** Epoch seconds when it happened. */ created_at?: number; /** The event's data. */ data: Record; /** The webhook delivery's id, the same on every retry of it. */ webhookId: string; } /** How `verifyOpenAIWebhook()` checks a delivery. */ export interface OpenAIWebhookVerifyOptions { /** How old a delivery may be, in seconds, before it is refused as a replay. Defaults to 300. */ toleranceSeconds?: number; /** Replaces the system clock, in milliseconds, for tests. */ now?: () => number; } /** * Checks a webhook delivery's signature against your endpoint's signing secret (`whsec_...`) and * returns its event. A delivery that is unsigned, signed with another secret, altered, or older than * the tolerance is refused with a `RealtimeError` of code `invalid_webhook_signature`. Pass the body * exactly as it arrived: reformatted JSON no longer matches its signature. */ export declare function verifyOpenAIWebhook(request: { headers: OpenAIWebhookHeaders; body: string | Uint8Array; }, secret: string, options?: OpenAIWebhookVerifyOptions): Promise; /** * Returns a function that exchanges an SDP offer, ready to put behind your own HTTP route. Give each * call its `tenantId`, such as the one your route authenticated, and with `credentials` the session * is made with that tenant's key. */ export declare function createOpenAIRealtimeSessionEndpoint(options: OpenAIRealtimeServerOptions): (sdp: string, signal?: AbortSignal, call?: { tenantId?: string; }) => Promise;