Skip to main content
kRouter
All posts
How kRouter works

One API for AI video: routing Grok Imagine through kRouter

kRouter proxies xAI's Grok Imagine video jobs on the same local endpoint as chat, audio and images. How submit-and-poll works, and what it does not do yet.

Kodelyth · The team behind kRouter
· Updated
5 min read

For a year, kRouter was described as an "LLM router." That description is now badly out of date. As of v0.5.111, kRouter proxies AI video generation -- a /v1/videos surface wrapping xAI's Grok Imagine -- bringing the modality count to eight: chat, text-to-speech, speech-to-text, image, video, embeddings, web search, and web fetch. All through one local endpoint.

One limit up front, because the headline could suggest otherwise: video works through one provider, xAI. More on that below.

The video surface

kRouter has a /v1/videos surface with four routes -- generations, edits, extensions, and status polling -- that proxy Grok Imagine's asynchronous jobs. Video generation is async by nature: you submit a job, get a request_id, and poll until the video is ready.

The proxy is deliberately transparent. It forwards your request body byte-for-byte and passes request_id, status, and video.url back verbatim. It refreshes an expired token once on a 401/403 and retries -- but it will never re-send a creation POST on a network error, because the job may already be running upstream and you do not want a duplicate.

Verified end to end

This is not a stub. The v0.5.111 release notes record a real Grok Imagine job submitted against a live xAI account:

submit → request_id: f00c3438… → poll → status: done
→ playable video URL at https://vidgen.x.ai/…

The stored xAI token had expired (8-hour TTL); kRouter refreshed it transparently and xAI accepted the job. Full round trip, not a mock.

How the async flow works

Because video is a polling workflow, the pattern is submit-then-poll. These requests come from the same machine as kRouter, so they need no key; from another machine, add -H "Authorization: Bearer <your-krouter-key>".

# 1. Submit a generation job
curl -i http://localhost:20128/v1/videos/generations \
  -H "Content-Type: application/json" \
  -d '{
    "model": "xai/grok-imagine-video",
    "prompt": "a timelapse of a city skyline at dusk"
  }'
# → { "request_id": "f00c3438..." }
#   plus a response header: x-9router-connection-id: <id>
 
# 2. Poll for status until done
curl http://localhost:20128/v1/videos/f00c3438... \
  -H "x-connection-id: <id from step 1>"
# → { "status": "pending", "progress": 40, ... }
# → { "status": "done", "video": { "url": "https://vidgen.x.ai/..." } }

The creation call returns only the request_id. Polling returns pending while xAI renders, then done with the video URL, or failed with an error.

The x-connection-id header matters if you have connected more than one xAI account. A job belongs to the account that created it, so kRouter returns that account's id on the creation response; send it back when you poll and the poll goes to the same account. With a single account you can leave it out.

What kRouter does around the job

kRouter handles the auth, the token refresh, and the format passthrough. A few behaviours worth knowing:

  • Account rotation only where it is safe. If xAI rejects a creation request with 401, 403 or 429 -- errors that come back before a job exists -- kRouter tries your next xAI account. A 5xx is returned to you rather than re-sent, because the job may already have been created.
  • Idempotency keys pass through. Send an Idempotency-Key header and kRouter forwards it to xAI.
  • Secrets stay out of errors. Bearer tokens and stored credentials are stripped from upstream error text before it reaches your client or the error shown in the dashboard.

Only xAI, for now

This is the part a single-API headline glosses over:

  • xAI Grok Imagine is the only wired video provider. A model id without a provider prefix is sent to xAI. Runway appears in kRouter's provider catalog with a video kind, but there is no video endpoint behind it, so a runwayml/... model returns "does not support video generation".
  • Combos do not work for video. A combo name in the model field returns 400 "Combos are not supported for video generation", so there is no automatic fallback to another video provider.
  • The catalog lists one model. GET /v1/models/video returns xai/grok-imagine-video. xAI's own docs now also show grok-imagine-video-1.5; kRouter passes the model name you send through to xAI, but its catalog has not caught up.

Why one endpoint for every modality matters

The point of routing video through kRouter is the same as routing chat, audio, and images through it: one base URL, one auth token, one surface for everything.

Before kRouter, adding video to an app meant a new SDK, a new API key, a new billing dashboard, and provider-specific job semantics. With kRouter, video is a model name against localhost:20128, using the same xAI connection that serves Grok chat.

The full modality map

kRouter is now a genuine multimodal gateway. The endpoints:

ModalityEndpointExample providers
Chat / code/v1/chat/completions, /v1/messagesClaude, GPT, Gemini, GLM, Kimi
Text-to-speech/v1/audio/speechOpenAI, Gemini, ElevenLabs, NVIDIA
Speech-to-text/v1/audio/transcriptionsWhisper, Deepgram, AssemblyAI
Image/v1/images/generationsOpenAI, Gemini, FLUX, Stability AI
Video/v1/videos/generationsxAI Grok Imagine only
Embeddings/v1/embeddingsOpenAI, Voyage, Jina
Web search/v1/searchTavily, Exa, Brave, Serper
Web fetch/v1/web/fetchFirecrawl, Jina Reader

See the multimodal gateway overview for the full story, the API reference for every route, or the multimodal skills docs for agent integration.

Common questions

Which video providers does kRouter support?

Only xAI's Grok Imagine. Runway is listed in the catalog but not wired for video, and there is no Veo, Sora or Kling support.

Can a combo fall back between video models?

No. Combos are rejected with a 400 on the video routes. Within xAI, kRouter can move a creation request to another connected xAI account when the first one is rejected with 401, 403 or 429.

Why do I need the x-connection-id header?

Only when you have more than one xAI account connected. A video job belongs to the account that created it, and the header tells kRouter which account to poll.

Does kRouter retry a failed video job?

Not after a network error or a 5xx, because the job may already exist upstream and a second POST would create and bill a second video.

Get started

npm install -g @sifxprime/krouter
krouter -t

Connect an xAI account in the dashboard, point any client at http://localhost:20128, and you have video generation on the same endpoint as everything else. Full setup at /install.

Kodelyth · The team behind kRouter

Published by Kodelyth, the team that builds kRouter. Posts are drafted with AI assistance and reviewed by a person before they go out. kRouter is free and MIT licensed.

Install kRouter