> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mka1.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Image generation

> Generate images through the Responses API.

Use image generation within a [Response](/docs/responses) when the model should generate an image as part of the interaction. For a direct prompt-to-image request, use the [standalone Images API](/docs/images-api).

<div className="legacy-section-link">
  <span id="images-api" />

  <p>This section has moved to <a href="/docs/images-api#images-api">Images API</a>.</p>
</div>

## Generate images

Use the `image_generation` tool to create images from text prompts. The model interprets your message, generates a prompt for the image model, and returns the result.

### Image generation models

| Model                   | Best for                                   |
| ----------------------- | ------------------------------------------ |
| `meetkai:flux-2-klein`  | Fast generation, general purpose (default) |
| `meetkai:z-image-turbo` | High-quality, detailed images              |

### Image generation options

| Parameter       | Options                                       | Default |
| --------------- | --------------------------------------------- | ------- |
| `size`          | `1024x1024`, `1024x1536`, `1536x1024`, `auto` | `auto`  |
| `quality`       | `low`, `medium`, `high`, `auto`               | `auto`  |
| `output_format` | `png`, `webp`, `jpeg`                         | `png`   |
| `background`    | `transparent`, `opaque`, `auto`               | `auto`  |

<CodeGroup>
  ```ts TypeScript SDK theme={null}
  import { SDK } from '@meetkai/mka1';
  import type { ResponseObject } from '@meetkai/mka1/models/components';

  const sdk = new SDK({ bearerAuth: 'Bearer <mka1-api-key>' });

  const result = await sdk.llm.responses.create({
    xOnBehalfOf: '<end-user-id>',
    responsesCreateRequest: {
      model: 'auto',
      input: 'Generate an image of a sunset over a mountain lake.',
      tools: [
        {
          type: 'image_generation',
          model: 'auto',
          quality: 'high',
          size: '1024x1024',
        },
      ],
    },
  }) as ResponseObject;

  // The output includes an image_generation_call item with a result URL
  const imageCall = result.output.find((item) => item.type === 'image_generation_call');
  console.log('Image URL:', imageCall?.result);
  ```

  ```ts OpenAI SDK theme={null}
  import OpenAI from 'openai';

  const openai = new OpenAI({
    apiKey: '<mka1-api-key>',
    baseURL: 'https://apigw.mka1.com/api/v1/llm/',
    defaultHeaders: { 'X-On-Behalf-Of': '<end-user-id>' },
  });

  const response = await openai.responses.create({
    model: 'auto',
    input: 'Generate an image of a sunset over a mountain lake.',
    tools: [{ type: 'image_generation' }],
    stream: false,
  });

  const imageCall = response.output.find((item) => item.type === 'image_generation_call');
  console.log('Image URL:', imageCall?.result);
  ```

  ```python Python SDK theme={null}
  from meetkai_mka1 import SDK

  sdk = SDK(bearer_auth="Bearer <mka1-api-key>")

  result = sdk.llm.responses.create(
      model="auto",
      input="Generate an image of a sunset over a mountain lake.",
      tools=[
          {
              "type": "image_generation",
              "model": "auto",
              "quality": "high",
              "size": "1024x1024",
              "output_format": "png",
          },
      ],
  )

  # The output includes an image_generation_call item with a result URL
  for item in result.output:
      if item.type == "image_generation_call":
          print("Image URL:", item.result)
  ```

  ```csharp C# SDK theme={null}
  using MeetKai.MKA1;
  using MeetKai.MKA1.Types.Components;
  using MeetKai.MKA1.Types.Requests;

  var sdk = new SDK(bearerAuth: "Bearer <mka1-api-key>");

  var result = await sdk.Llm.Responses.CreateAsync(new ResponsesCreateRequest()
  {
      Model = "auto",
      Input = ResponsesCreateRequestInput.CreateStr(
          "Generate an image of a sunset over a mountain lake."),
      Tools = new List<ResponsesCreateRequestTool>
      {
          ResponsesCreateRequestTool.CreateImageGenerationToolDefinition(
              new ImageGenerationToolDefinition()
              {
                  Model = "meetkai:flux-2-klein",
                  Quality = ImageGenerationToolDefinitionQuality.High,
                  Size = ImageGenerationToolDefinitionSize.OneThousandAndTwentyFourx1024,
              }
          ),
      },
  });

  // The output includes an image_generation_call item with a result URL
  ```

  ```bash CLI theme={null}
  mka1 llm responses create --body '{
    "model": "auto",
    "input": "Generate an image of a sunset over a mountain lake.",
    "tools": [
      {
        "type": "image_generation",
        "model": "auto",
        "quality": "high",
        "size": "1024x1024",
        "output_format": "png"
      }
    ]
  }'
  ```

  ```bash Bash theme={null}
  curl https://apigw.mka1.com/api/v1/llm/responses \
    --request POST \
    --header 'Content-Type: application/json' \
    --header 'Authorization: Bearer <mka1-api-key>' \
    --header 'X-On-Behalf-Of: <end-user-id>' \
    --data '{
      "model": "auto",
      "input": "Generate an image of a sunset over a mountain lake.",
      "tools": [
        {
          "type": "image_generation",
          "model": "auto",
          "quality": "high",
          "size": "1024x1024",
          "output_format": "png"
        }
      ]
    }'
  ```
</CodeGroup>

The response includes an `image_generation_call` item with the generated image URL and the revised prompt used by the image model:

```json theme={null}
{
  "status": "completed",
  "output": [
    {
      "type": "message",
      "role": "assistant",
      "content": [
        {
          "type": "output_text",
          "text": "I'll generate an image of a beautiful sunset over a mountain lake for you."
        }
      ]
    },
    {
      "type": "image_generation_call",
      "id": "ig_abc123",
      "status": "completed",
      "result": "<Generated Image URL>",
      "revised_prompt": "A breathtaking sunset over a pristine mountain lake, with golden and orange hues reflecting on the calm water surface. Snow-capped mountain peaks in the background, dramatic clouds in the sky with vibrant sunset colors of pink, purple, and orange.",
      "size": "auto",
      "quality": "auto",
      "output_format": "png"
    }
  ]
}
```

The `result` field contains a URL to the generated image. The `revised_prompt` shows the expanded prompt the image model used — the LLM enhances your brief instruction into a detailed image description.

### Force image generation

Use `tool_choice` to ensure the model generates an image rather than responding with text only.

<CodeGroup>
  ```ts TypeScript SDK theme={null}
  const result = await sdk.llm.responses.create({
    responsesCreateRequest: {
      model: 'auto',
      input: 'A red circle on a white background.',
      tools: [{ type: 'image_generation' }],
      toolChoice: { type: 'image_generation' },
    },
  });
  ```

  ```ts OpenAI SDK theme={null}
  const response = await openai.responses.create({
    model: 'auto',
    input: 'A red circle on a white background.',
    tools: [{ type: 'image_generation' }],
    tool_choice: { type: 'image_generation' },
    stream: false,
  });
  ```

  ```python Python SDK theme={null}
  result = sdk.llm.responses.create(
      model="auto",
      input="A red circle on a white background.",
      tools=[{"type": "image_generation"}],
      tool_choice={"type": "image_generation"},
  )
  ```

  ```csharp C# SDK theme={null}
  var result = await sdk.Llm.Responses.CreateAsync(new ResponsesCreateRequest()
  {
      Model = "auto",
      Input = ResponsesCreateRequestInput.CreateStr("A red circle on a white background."),
      Tools = new List<ResponsesCreateRequestTool>
      {
          ResponsesCreateRequestTool.CreateImageGenerationToolDefinition(
              new ImageGenerationToolDefinition()
          ),
      },
      ToolChoice = ToolChoice.CreateHostedToolChoice(new HostedToolChoice()
      {
          Type = HostedToolChoiceType.ImageGeneration,
      }),
  });
  ```

  ```bash CLI theme={null}
  mka1 llm responses create --body '{
    "model": "auto",
    "input": "A red circle on a white background.",
    "tools": [{ "type": "image_generation" }],
    "tool_choice": { "type": "image_generation" }
  }'
  ```

  ```bash Bash theme={null}
  curl https://apigw.mka1.com/api/v1/llm/responses \
    --request POST \
    --header 'Content-Type: application/json' \
    --header 'Authorization: Bearer <mka1-api-key>' \
    --data '{
      "model": "auto",
      "input": "A red circle on a white background.",
      "tools": [{ "type": "image_generation" }],
      "tool_choice": { "type": "image_generation" }
    }'
  ```
</CodeGroup>

### Image output structure

The response `output` array contains these items when an image is generated:

1. `function_call` — the model's call to the image generation tool with the refined prompt
2. `image_generation_call` — the generation result with `status: "completed"` and `result` (image URL)
3. `function_call_output` — the raw tool output containing the URL
4. `message` — the model's text response describing or referencing the image

Image URLs expire after 1 hour. Download or cache them if you need long-term access.
