Files
openclaw/extensions/xai/realtime-voice-auth.runtime.ts
Vincent Koc e35d22807e perf(xai): lazy-load optional capability runtimes (#119374)
Punchcard-Session: coral-workshop-workshop-3f
2026-08-05 11:26:40 +08:00

23 lines
914 B
TypeScript

import type { OpenClawConfig } from "openclaw/plugin-sdk/provider-auth";
import { resolveApiKeyForProvider } from "openclaw/plugin-sdk/provider-auth-runtime";
import { normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
export async function resolveXaiRealtimeApiKey(
configApiKey: string | undefined,
cfg: OpenClawConfig | undefined,
): Promise<string> {
const direct =
normalizeOptionalString(configApiKey) ?? normalizeOptionalString(process.env.XAI_API_KEY);
if (direct) {
return direct;
}
const auth = await resolveApiKeyForProvider({ provider: "xai", cfg });
const oauthKey = normalizeOptionalString(auth?.apiKey);
if (oauthKey) {
return oauthKey;
}
throw new Error(
"xAI credentials missing for realtime voice. Sign in with `openclaw onboard --auth-choice xai-oauth`, run `openclaw onboard --auth-choice xai-api-key`, or set XAI_API_KEY.",
);
}