Skip to content

Add an xAI preset: images, videos and speech with Grok Imagine - #89

Merged
nasser1941 merged 1 commit into
mainfrom
feat/xai
Oct 6, 2026
Merged

nasser1941 merged 1 commit into
mainfrom
feat/xai

Conversation

@nasser1941

Copy link
Copy Markdown
Owner

What

lcode mcp add xai first asks for an xAI API key: typed hidden, or taken from XAI_API_KEY if it's set. It then runs lcode-mcp-xai, a new MCP server shipped with lcode for xAI's Grok Imagine and text to speech APIs.

Tool API
generate_image POST /v1/images/generations: 1–10 images, aspect ratio, 1k/2k, model grok-imagine-image-2.0 (or -quality, or the basic one), as base64
edit_image POST /v1/images/edits, with the local image as a data URL
generate_video POST /v1/videos/generations, then polls GET /v1/videos/{id}: 1–15 s, up to 1080p, optionally from a local start image. Waits up to 10 minutes and downloads the MP4
video_status Picks up a video that took longer than that
text_to_speech POST /v1/tts: 26 voices, 20 languages, MP3 or WAV
  • Where files go: generated/ in the project, or a path the model is asked for. An extension is added when missing, and nothing is overwritten.
  • Errors: xAI's own messages reach the model, such as a moderation refusal, a bad key (with a hint about XAI_API_KEY) or a rate or credit limit.
  • Music: xAI has no music generation API, so there's no music tool.
  • Asking first: lcode asks before every call, since each is billed to the user's xAI account. "allow" in mcp.json turns that off per tool.
  • Docs: a section in the MCP guide (tools, costs, privacy), a catalog row, and the README.

Tests

  • tests/test_xai.py (6 tests) uses a fake xAI API. It covers:
    • the request bodies of every tool, and the saved files (names, extensions, no overwriting);
    • edits sending a data URL;
    • video polling, the request id handed back after the wait, and video_status;
    • TTS JSON with base64 audio;
    • moderation and bad-key errors;
    • the preset asking for the key.
  • Real run with Qwen3.6 35B through Ollama against the fake API, with lcode's stdio MCP transport. The request was "make me an image of a red fox saved as assets/fox.png, a voice line in the Leo voice, and a 4 second video of the fox running starting from that image". The model called generate_image, text_to_speech and generate_video with the image as the start frame, and all three files were saved.
  • Not run against the real xAI API: that needs a key and is billed.

🤖 Generated with Claude Code

lcode mcp add xai asks for an xAI API key and runs lcode-mcp-xai, a new
MCP server shipped with lcode for xAI's Grok Imagine and text to speech
APIs: generate_image (1-10 images, aspect ratio, 1k/2k), edit_image (a
local image, sent as a data URL), generate_video (1-15 s, optionally
from a local start image; waits up to 10 minutes and downloads the MP4),
video_status (for one that took longer) and text_to_speech (26 voices,
MP3 or WAV). Files are saved in generated/ in the project or where the
model is asked to save them. xAI's error messages, such as a moderation
refusal or a bad key, reach the model. xAI has no music API.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@nasser1941
nasser1941 merged commit 9ebffcb into main Oct 6, 2026
12 checks passed
@nasser1941
nasser1941 deleted the feat/xai branch October 6, 2026 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant