mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-09-11 20:27:54 +02:00
cr
This commit is contained in:
@@ -31,6 +31,35 @@ import {
|
||||
OnConflictBehavior,
|
||||
} from "./types.js";
|
||||
|
||||
/**
|
||||
* Get the API key from the environment.
|
||||
* Precedence:
|
||||
* 1. explicit argument
|
||||
* 2. LANGGRAPH_API_KEY
|
||||
* 3. LANGSMITH_API_KEY
|
||||
* 4. LANGCHAIN_API_KEY
|
||||
*
|
||||
* @param apiKey - Optional API key provided as an argument
|
||||
* @returns The API key if found, otherwise undefined
|
||||
*/
|
||||
export function getApiKey(apiKey?: string): string | undefined {
|
||||
if (apiKey) {
|
||||
return apiKey;
|
||||
}
|
||||
|
||||
const prefixes = ["LANGGRAPH", "LANGSMITH", "LANGCHAIN"];
|
||||
|
||||
for (const prefix of prefixes) {
|
||||
const envKey = process.env[`${prefix}_API_KEY`];
|
||||
if (envKey) {
|
||||
// Remove surrounding quotes
|
||||
return envKey.trim().replace(/^["']|["']$/g, "");
|
||||
}
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
interface ClientConfig {
|
||||
apiUrl?: string;
|
||||
apiKey?: string;
|
||||
@@ -58,12 +87,7 @@ class BaseClient {
|
||||
this.timeoutMs = config?.timeoutMs || 12_000;
|
||||
this.apiUrl = config?.apiUrl || "http://localhost:8123";
|
||||
this.defaultHeaders = config?.defaultHeaders || {};
|
||||
if (config?.apiKey != null) {
|
||||
this.defaultHeaders["X-Api-Key"] = config.apiKey;
|
||||
} else if (process.env.LANGCHAIN_API_KEY) {
|
||||
// Attempt to read the API key from the environment
|
||||
this.defaultHeaders["X-Api-Key"] = process.env.LANGCHAIN_API_KEY;
|
||||
}
|
||||
this.defaultHeaders["X-Api-Key"] = getApiKey(config?.apiKey);
|
||||
}
|
||||
|
||||
protected prepareFetchOptions(
|
||||
|
||||
Reference in New Issue
Block a user