Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/llm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,11 @@ export type LlamaCppConfig = {
* Env: CLAWMEM_LLM_NO_THINK
*/
remoteLlmNoThink?: boolean;
/**
* API key for remote LLM server. Sent as Bearer token.
* Env: CLAWMEM_LLM_API_KEY
*/
remoteLlmApiKey?: string;
/**
* Inactivity timeout in ms before unloading contexts (default: 2 minutes, 0 to disable).
*
Expand Down Expand Up @@ -313,6 +318,7 @@ export class LlamaCpp implements LLM {
private remoteLlmModel: string;
private remoteLlmReasoningEffort: string | null;
private remoteLlmNoThink: boolean;
private remoteLlmApiKey: string | null;

// Ensure we don't load the same model concurrently (which can allocate duplicate VRAM).
private embedModelLoadPromise: Promise<LlamaModel> | null = null;
Expand Down Expand Up @@ -349,6 +355,7 @@ export class LlamaCpp implements LLM {
this.remoteLlmModel = normalizedRemoteLlmModel || "qwen3";
this.remoteLlmReasoningEffort = normalizeRemoteLlmReasoningEffort(config.remoteLlmReasoningEffort);
this.remoteLlmNoThink = config.remoteLlmNoThink ?? true;
this.remoteLlmApiKey = config.remoteLlmApiKey || null;
this.inactivityTimeoutMs = config.inactivityTimeoutMs ?? DEFAULT_INACTIVITY_TIMEOUT_MS;
this.disposeModelsOnInactivity = config.disposeModelsOnInactivity ?? false;
}
Expand Down Expand Up @@ -1035,9 +1042,13 @@ export class LlamaCpp implements LLM {
if (this.remoteLlmReasoningEffort) {
body.reasoning_effort = this.remoteLlmReasoningEffort;
}
const headers: Record<string, string> = { "Content-Type": "application/json" };
if (this.remoteLlmApiKey) {
headers["Authorization"] = `Bearer ${this.remoteLlmApiKey}`;
}
const resp = await fetch(buildRemoteChatCompletionsUrl(this.remoteLlmUrl!), {
method: "POST",
headers: { "Content-Type": "application/json" },
headers,
body: JSON.stringify(body),
signal,
});
Expand Down Expand Up @@ -1374,6 +1385,7 @@ export function getDefaultLlamaCpp(): LlamaCpp {
if (!raw) return undefined;
return !["0", "false", "no", "off"].includes(raw);
})(),
remoteLlmApiKey: process.env.CLAWMEM_LLM_API_KEY || undefined,
});
}
return defaultLlamaCpp;
Expand Down
3 changes: 3 additions & 0 deletions src/openclaw/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ const clawmemPlugin = {
...(pluginCfg.gpuLlmNoThink !== undefined
? { CLAWMEM_LLM_NO_THINK: String(pluginCfg.gpuLlmNoThink) }
: {}),
...(pluginCfg.gpuLlmApiKey
? { CLAWMEM_LLM_API_KEY: pluginCfg.gpuLlmApiKey as string }
: {}),
...(pluginCfg.gpuRerank ? { CLAWMEM_RERANK_URL: pluginCfg.gpuRerank as string } : {}),
CLAWMEM_PROFILE: profile,
},
Expand Down