nexu-io/open-design · error · Error

grok image ${resp.status}: ${truncate(text, 240)}

Error message

grok image ${resp.status}: ${truncate(text, 240)}

What it means

Thrown when `POST /v1/images/generations` to xAI returns a non-2xx status. The message carries the HTTP status plus up to 240 chars of body, surfacing the xAI error (auth, model access, moderation, invalid `aspect_ratio`).

Source

Thrown at apps/daemon/src/media/index.ts:1638

  const aspectRatio = grokAspectFor(ctx.aspect);
  const body = {
    model: ctx.wireModel,
    prompt: ctx.prompt || 'A high-quality reference image.',
    n: 1,
    aspect_ratio: aspectRatio,
    response_format: 'b64_json',
  };
  const resp = await fetch(`${baseUrl}/images/generations`, withMediaRequestInit(ctx, {
    method: 'POST',
    headers: {
      'authorization': `Bearer ${credentials.apiKey}`,
      'content-type': 'application/json',
    },
    body: JSON.stringify(body),
  }));
  const text = await resp.text();
  if (!resp.ok) {
    throw new Error(`grok image ${resp.status}: ${truncate(text, 240)}`);
  }
  let data: any;
  try {
    data = JSON.parse(text);
  } catch {
    throw new Error(`grok image non-JSON: ${truncate(text, 200)}`);
  }
  const entry = data && Array.isArray(data.data) ? data.data[0] : null;
  if (!entry) throw new Error('grok image response had no data[0]');
  let bytes;
  if (entry.b64_json) {
    bytes = Buffer.from(entry.b64_json, 'base64');
  } else if (entry.url) {
    const imgResp = await fetch(entry.url, withMediaRequestInit(ctx));
    if (!imgResp.ok) throw new Error(`grok image fetch ${imgResp.status}`);
    bytes = Buffer.from(await imgResp.arrayBuffer());
  } else {
    throw new Error('grok image response missing b64_json/url');

View on GitHub (pinned to 5be4028344)

Solutions

  1. Inspect the embedded status+body: 401 → refresh the key/OAuth token; 403 → confirm the Imagine model is enabled for the account tier; 400 → adjust aspect; 429 → back off.
  2. Re-run `hermes auth add xai-oauth` if using OAuth and the token expired.
  3. Verify the `baseUrl` (default `https://api.x.ai/v1`) and that the model name matches a valid xAI image model.
Defensive patterns

Strategy: try-catch

Try / catch

try {
  return await renderGrokImage(ctx, credentials);
} catch (err) {
  const msg = err instanceof Error ? err.message : String(err);
  if (/image 40[13]/.test(msg)) { throw new Error('xAI auth failed — refresh XAI_API_KEY or re-run OAuth'); }
  if (/permission|forbidden/i.test(msg)) { throw new Error('Grok Imagine model not enabled for this account tier'); }
  if (/image 429/.test(msg)) { /* back off */ }
  throw err;
}

Prevention

When it happens

Trigger: `resp.ok === false` on the Grok image call. Concretely: 401 from an invalid/expired key or OAuth token, 403 because the Imagine model isn't enabled for the account/tier, 400 from an unsupported `aspect_ratio` (via `grokAspectFor`), or 429 rate limit.

Common situations: (1) `XAI_API_KEY` revoked or OAuth token expired; (2) Imagine model not available on the user's xAI tier; (3) aspect ratio not in xAI's supported set; (4) prompt tripped xAI moderation; (5) rate limit on a shared key.

Related errors


AI-assisted analysis of nexu-io/open-design@5be4028344 (2026-08-12). Data as JSON: /api/errors/22004e929bd64d3d. Report an issue: GitHub.