import type { AsyncResource } from "webappwiz/disposable"; import type { CredentialSource } from "./credential-source.js"; /** What `CredentialProxy.listen` forwards, and which key it puts in. */ export interface CredentialProxyOptions { /** * Where every request goes: an `https://` origin, with a path each * request's own is put under when it has one, such as * `https://api.openai.com/v1`. Nothing else is ever reached. */ upstream: string; /** The credential's name in the source, such as `ANTHROPIC_API_KEY`. */ credential: string; /** * The header the key travels in, such as `x-api-key` for Anthropic or * `authorization` for OpenAI. The client sends its placeholder there, and * the proxy puts the real key there in its place. */ header: string; /** The word before the key in that header, such as `Bearer`; none by default. */ scheme?: string; } /** * A loopback HTTP proxy that keeps an API key from the program it serves, * such as an agent's CLI. The program gets `url` as its provider's base URL * and `placeholder` as its key; the proxy forwards each of its requests to * the one upstream with the placeholder swapped for the real key, which it * reads from its source on every request, so a rotated key needs no * restart. The program never holds the key, so it cannot print, log or send * it anywhere. * * It listens on 127.0.0.1 alone, on a free port, and refuses with a 401, * reaching no upstream, any request without its own placeholder, which is * random for each proxy, so another local process, or another task's agent, * cannot spend the key through it. It never follows a redirect, so the key * goes to the upstream origin and nowhere else, and it passes responses * through as they stream, server-sent events and compressed bodies alike. * No response, error or log of its own ever holds the key. * * The placeholder is only as private as the program's environment: on a * machine where the program runs as the proxy's own user, make the process * holding the key undumpable (`makeUndumpable()` from `webappwiz/system`), * or run the program in a container. */ export declare class CredentialProxy implements AsyncResource { private readonly server; /** The base URL to hand the program, as `http://127.0.0.1:`. */ readonly url: string; /** The key to hand the program in place of the real one. */ readonly placeholder: string; private constructor(); /** Starts a proxy for one credential, reading it from `source`. */ static listen(source: CredentialSource, opts: CredentialProxyOptions): CredentialProxy; /** Stops listening and cuts every request still streaming. */ disposeAsync(): Promise; }