Skip to content

Image Generation

Generate an image from a text prompt.

This example assumes using Xai; is in scope and apiKey contains your Xai API key.

1
2
3
4
5
6
7
8
var client = new XaiClient(apiKey);

// Generate an image using the Grok Imagine model.
var response = await client.Images.CreateImageAsync(
    model: "grok-imagine-image",
    prompt: "A simple red circle on a white background");

Console.WriteLine(response.Data![0].Url);