@langchain/langgraph-sdk
Version:
Client library for interacting with the LangGraph API
126 lines (125 loc) • 4.23 kB
text/typescript
import { AsyncCaller, AsyncCallerParams } from "../utils/async_caller.cjs";
import { IdleReconnectMode } from "../utils/stream.cjs";
import { StreamProtocol } from "../types.cjs";
//#region src/client/base.d.ts
type HeaderValue = string | undefined | null;
/**
* Get the API key from the environment.
* Precedence:
* 1. explicit argument (if string)
* 2. LANGGRAPH_API_KEY
* 3. LANGSMITH_API_KEY
* 4. LANGCHAIN_API_KEY
*
* @param apiKey - API key provided as an argument. If null, skips environment lookup. If undefined, tries environment.
* @returns The API key if found, otherwise undefined
*/
declare function getApiKey(apiKey?: string | null): string | undefined;
type RequestHook = (url: URL, init: RequestInit) => Promise<RequestInit> | RequestInit;
/**
* Configuration for {@link BaseClient} and the exported LangGraph SDK
* {@link Client}.
*/
interface ClientConfig {
/**
* Base URL of the LangGraph API server.
*
* Defaults to `http://localhost:8123`, unless the runtime provides a
* `langgraph_api:url` global override.
*/
apiUrl?: string;
/**
* API key for authentication.
* - If a string is provided, that key will be used
* - If undefined (default), the key will be auto-loaded from environment variables (LANGGRAPH_API_KEY, LANGSMITH_API_KEY, or LANGCHAIN_API_KEY)
* - If null, no API key will be set (skips auto-loading)
*/
apiKey?: string | null;
/**
* Options forwarded to the internal {@link AsyncCaller}, such as retry,
* concurrency, or custom `fetch` behavior.
*/
callerOptions?: AsyncCallerParams;
/**
* Default timeout, in milliseconds, applied to client requests.
*
* Per-request `timeoutMs` values override this default. Passing `null`
* at the request level disables the configured timeout for that request.
*/
timeoutMs?: number;
/**
* Headers applied to every request.
*
* The configured API key, when present, is added as the `x-api-key`
* header after these defaults are initialized.
*/
defaultHeaders?: Record<string, HeaderValue>;
/**
* Hook for inspecting or mutating a request before it is sent.
*
* Receives the resolved URL and prepared `RequestInit`; return the
* original init or a replacement object to continue the request.
*/
onRequest?: RequestHook;
/**
* Streaming protocol used by stream-capable endpoints.
*
* Defaults to `"legacy"` for backwards compatibility.
*/
streamProtocol?: StreamProtocol;
}
declare class BaseClient {
#private;
protected asyncCaller: AsyncCaller;
protected timeoutMs: number | undefined;
protected apiUrl: string;
protected defaultHeaders: Record<string, HeaderValue>;
protected onRequest?: RequestHook;
protected streamProtocol: StreamProtocol;
constructor(config?: ClientConfig);
protected prepareFetchOptions(path: string, options?: RequestInit & {
json?: unknown;
params?: Record<string, unknown>;
timeoutMs?: number | null;
withResponse?: boolean;
dedupe?: boolean;
}): [url: URL, init: RequestInit];
protected fetch<T>(path: string, options: RequestInit & {
json?: unknown;
params?: Record<string, unknown>;
timeoutMs?: number | null;
signal: AbortSignal | undefined;
withResponse: true;
}): Promise<[T, Response]>;
protected fetch<T>(path: string, options?: RequestInit & {
json?: unknown;
params?: Record<string, unknown>;
timeoutMs?: number | null;
signal: AbortSignal | undefined;
withResponse?: false;
dedupe?: boolean;
}): Promise<T>;
protected streamWithRetry<T extends {
id?: string;
event: string;
data: unknown;
}>(config: {
endpoint: string;
method?: string;
signal?: AbortSignal;
headers?: Record<string, string>;
params?: Record<string, unknown>;
json?: unknown;
maxRetries?: number;
idleReconnect?: IdleReconnectMode;
onReconnect?: (options: {
attempt: number;
lastEventId?: string;
cause: unknown;
}) => void;
onInitialResponse?: (response: Response) => void | Promise<void>;
}): AsyncGenerator<T>;
}
//#endregion
export { BaseClient, ClientConfig, HeaderValue, RequestHook, getApiKey };
//# sourceMappingURL=base.d.cts.map