Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Live calls: say when the OpenAI account has no credit left, not "try again in a moment"
AdityaUmaledb288b4d8ffc
diff --git a/server/live-call.test.ts b/server/live-call.test.tsindex 5d9971bed9..027531e2d0 100644--- a/server/live-call.test.ts+++ b/server/live-call.test.ts@@ -107,6 +107,16 @@ describe("createLiveSession", () => {}});+ it("says an OpenAI account with no credit left needs billing, not another try", async () => {+ const noCredit = vi.fn(async () => new Response(JSON.stringify({ error: { type: "insufficient_quota", code: "insufficient_quota", message: "You exceeded your current quota" } }), { status: 429 }));+ const error = await createLiveSession({ key: "k", sdp: OFFER, bot: BOT, history: [], cloudHome: false, fetchImpl: noCredit }).catch((e) => e);+ expect(error).toMatchObject({ status: 429, message: expect.stringContaining("no credit left") });+ expect(error.message).not.toContain("Try again in a moment");+ const limited = vi.fn(async () => new Response(JSON.stringify({ error: { type: "requests", code: "rate_limit_exceeded" } }), { status: 429 }));+ await expect(createLiveSession({ key: "k", sdp: OFFER, bot: BOT, history: [], cloudHome: false, fetchImpl: limited }))+ .rejects.toMatchObject({ status: 429, message: expect.stringContaining("limiting Live sessions") });+ });+it("reports network failures and malformed answers", async () => {const offline = vi.fn(async () => { throw new TypeError("fetch failed"); });await expect(createLiveSession({ key: "k", sdp: OFFER, bot: BOT, history: [], cloudHome: false, fetchImpl: offline })).rejects.toMatchObject({ status: 502, message: expect.stringContaining("Could not reach OpenAI") });diff --git a/server/live-call.ts b/server/live-call.tsindex 89dd50ae6f..39b9b77b79 100644--- a/server/live-call.ts+++ b/server/live-call.ts@@ -257,9 +257,10 @@ export async function createLiveSession(input: CreateLiveSessionInput): Promise<);}if (!response.ok) {- const failure = await response.json().catch(() => null) as { error?: { param?: unknown } } | null;+ const failure = await response.json().catch(() => null) as { error?: { param?: unknown; code?: unknown } } | null;const param = typeof failure?.error?.param === "string" ? failure.error.param : undefined;- throw new LiveSessionError(liveErrorMessage(response.status, param, endpoint.provider), response.status === 429 ? 429 : 502);+ const code = typeof failure?.error?.code === "string" ? failure.error.code : undefined;+ throw new LiveSessionError(liveErrorMessage(response.status, param, endpoint.provider, code), response.status === 429 ? 429 : 502);}const payload = await response.json().catch(() => null) as { session?: { id?: unknown }; transport?: { sdp?: unknown } } | null;const sessionId = payload?.session?.id;@@ -270,7 +271,8 @@ export async function createLiveSession(input: CreateLiveSessionInput): Promise<return { sessionId, sdp };}-export function liveErrorMessage(status: number, param?: string, provider: LiveProvider = "openai"): string {+/** `code` is the provider's `error.code`: OpenAI answers 429 `insufficient_quota` when the account has no credit left, which waiting never fixes. */+export function liveErrorMessage(status: number, param?: string, provider: LiveProvider = "openai", code?: string): string {const name = liveProviderName(provider);if (status === 400) {return param && /voice/i.test(param)@@ -286,6 +288,7 @@ export function liveErrorMessage(status: number, param?: string, provider: LivePif (status === 401) return "OpenAI rejected the API key. Check the key for Live calls.";if (status === 403) return "This OpenAI project has no access to GPT-Live. Check the project's model access and billing.";if (status === 404) return "GPT-Live is not available for this OpenAI project.";+ if (status === 429 && code === "insufficient_quota") return "This OpenAI account has no credit left for Live calls. Add credit or raise the spending limit in OpenAI's billing settings, then call again.";if (status === 429) return "OpenAI is limiting Live sessions right now (rate limit or quota). Try again in a moment.";}if (status >= 500) return `${name} had a problem starting the call. Try again in a moment.`;