{"record":{"id":"ad97cab51492c50d","repo":"can1357/oh-my-pi","slug":"no-xai-credentials-run-login-xai-grok-oauth-s","errorCode":null,"errorMessage":"No xAI credentials. Run /login → xAI Grok OAuth (SuperGrok or X Premium+) or set XAI_API_KEY.","messagePattern":"No xAI credentials\\. Run /login → xAI Grok OAuth \\(SuperGrok or X Premium\\+\\) or set XAI_API_KEY\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/tools/image-gen.ts","lineNumber":1478,"sourceCode":"\t\t\t\t\t\t\tdetails: {\n\t\t\t\t\t\t\t\tprovider,\n\t\t\t\t\t\t\t\tmodel,\n\t\t\t\t\t\t\t\timageCount: parsed.images.length,\n\t\t\t\t\t\t\t\timagePaths,\n\t\t\t\t\t\t\t\timages: parsed.images,\n\t\t\t\t\t\t\t\tresponseText,\n\t\t\t\t\t\t\t\tusage: parsed.usage,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\tif (provider === \"xai\") {\n\t\t\t\t\t\tif (!ctx.modelRegistry) {\n\t\t\t\t\t\t\tthrow new Error(\"Missing modelRegistry for xAI image generation\");\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst xaiCreds = await resolveXAIHttpCredentials(ctx.modelRegistry, resolvedModel);\n\t\t\t\t\t\tif (!xaiCreds) {\n\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t\"No xAI credentials. Run /login → xAI Grok OAuth (SuperGrok or X Premium+) or set XAI_API_KEY.\",\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst prompt = assemblePrompt(params);\n\t\t\t\t\t\tconst aspectRatio = params.aspect_ratio ?? \"1:1\";\n\t\t\t\t\t\tconst xaiResolution = resolveXAIResolution(params.image_size);\n\n\t\t\t\t\t\tconst isEdit = resolvedImages.length > 0;\n\t\t\t\t\t\tif (isEdit && resolvedImages.length > XAI_MAX_EDIT_IMAGES) {\n\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t`xAI image edits accept up to ${XAI_MAX_EDIT_IMAGES} reference images; got ${resolvedImages.length}.`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst xaiBaseBody: XAIImageRequestBase = {\n\t\t\t\t\t\t\tmodel: resolvedModel,\n\t\t\t\t\t\t\tprompt,","sourceCodeStart":1460,"sourceCodeEnd":1496,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/tools/image-gen.ts#L1460-L1496","documentation":"Thrown when resolveXAIHttpCredentials cannot find any xAI credentials in the model registry: neither an xAI Grok OAuth login (SuperGrok / X Premium+) nor an XAI_API_KEY environment variable. The xAI image endpoint requires authenticated HTTP calls, so without credentials the provider is skipped/aborted.","triggerScenarios":"Running image generation (or edit) routed to provider=xai with no xAI OAuth session and XAI_API_KEY unset or empty in the environment, at image-gen.ts:1478.","commonSituations":"Fresh machine without /login; CI environment lacking XAI_API_KEY; user logged into xAI via a different config dir; XAI_API_KEY typo'd (e.g. XAI_KEY) or scoped to a shell profile not loaded by the CLI.","solutions":["Run /login in the agent and choose xAI Grok OAuth (SuperGrok or X Premium+).","Export XAI_API_KEY with a valid xAI API key: export XAI_API_KEY=xai-...","Verify the key is set in the environment the CLI actually sees (echo $XAI_API_KEY in the same shell/CI job).","Pick a different credentialed provider (OPENAI_API_KEY, GEMINI_API_KEY, etc.) if xAI access is unavailable."],"exampleFix":"// before\n$ omp -p \"generate an image\"\n// after\n$ export XAI_API_KEY=xai-...\n$ omp -p \"generate an image\"","handlingStrategy":"validation","validationCode":"if (!process.env.XAI_API_KEY) {\n  console.error('xAI not configured: run /login (xAI Grok OAuth) or set XAI_API_KEY');\n  process.exit(1);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await imageGen({ provider: 'xai', ...params });\n} catch (err) {\n  if (err instanceof Error && err.message.includes('No xAI credentials')) {\n    console.error('Set XAI_API_KEY or complete xAI OAuth via /login before retrying.');\n  } else throw err;\n}","preventionTips":["Run /login once per machine and confirm OAuth state persists","Export XAI_API_KEY in CI secrets and shell profiles the CLI actually loads","Probe credentials at app startup, not at first image request","Use the exact env var name XAI_API_KEY (no variants)"],"tags":["authentication","credentials","xai","image-generation"],"backgroundTag":"missing-api-key","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}