Files
openclaw/extensions/xai/realtime-voice-auth.runtime.ts

29 lines
1.1 KiB
TypeScript

import { resolveAgentDir } from "openclaw/plugin-sdk/agent-runtime";
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,
agentId?: string,
): Promise<string> {
const direct =
normalizeOptionalString(configApiKey) ?? normalizeOptionalString(process.env.XAI_API_KEY);
if (direct) {
return direct;
}
const auth = await resolveApiKeyForProvider({
provider: "xai",
cfg,
...(cfg && agentId ? { agentDir: resolveAgentDir(cfg, agentId) } : {}),
});
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.",
);
}