# Generate an image

`POST https://api.vidmoat.com/v1/ai/images`

- Scope: `ai.image`
- Cost: 60 credits Grok; OpenAI/Vertex from 128 credits

Generate a still with optional referenceUrls (up to 5 images: your uploads or public HTTPS images). provider accepts grok, openai, vertex or auto (default). quoteOnly:true returns the initial and maximum credits without spending. Retain provider:auto with the quoted maxCredits to allow safe quota fallback; explicit providers never switch. OpenAI GPT Image 2.5 Flare costs 128 at 1k or 256 at 2k plus 8 per reference; Vertex costs 128/192 plus 2 per reference. Only the successful asset is charged. Studio.

### Body

- `prompt` (string, required): Up to 800 characters.
- `provider` (enum, optional, default `auto`): Who generates it. One of `auto`, `grok`, `openai`, `vertex`.
- `resolution` (enum, optional, default `2k`): Affects OpenAI and Vertex prices. One of `1k`, `2k`.
- `aspectRatio` (string, optional): For example `16:9`, `9:16`, `1:1`, `4:5`, `21:9`.
- `referenceUrls` (array of strings, optional): Up to 5 reference images: your upload URLs (png, jpg, webp, avif) or public HTTPS URLs.
- `maxCredits` (number, optional): Never spend more than this.
- `quoteOnly` (boolean, optional): `true` returns the route and price without generating or charging.

## Response

Returns `200`.

### Response fields

- `url` (string): The image. Use as a clip `src`.
- `route` (object): The provider route chosen: `provider`, `model`, `credits`, `maxCredits`, `reason` and `policy` (and `voiceId` for speech).
- `credits` (object): `{ charged, remaining }`: what this call cost and the balance after it.
- `hint` (string): What to do with it.

> **Tip: With a test key.** Test keys return a sample image and spend nothing. `quoteOnly` is ignored on test keys.

## Errors

Besides the errors any request can get ([authentication](https://developer.vidmoat.com/developer/docs/authentication#when-a-request-is-refused), [rate limits](https://developer.vidmoat.com/developer/docs/rate-limits)):

| Status | Code | When |
| --- | --- | --- |
| 400 | [`invalid_request`](https://developer.vidmoat.com/developer/docs/errors#invalid_request) | No prompt, a refused reference, or no provider matches the options and `maxCredits`. |
| 402 | [`plan_required`](https://developer.vidmoat.com/developer/docs/errors#plan_required) | The plan has no image generation. |
| 402 | [`insufficient_credits`](https://developer.vidmoat.com/developer/docs/errors#insufficient_credits) | The balance cannot cover the call. Nothing ran. `remaining` is the balance. |
| 422 | [`prompt_rejected`](https://developer.vidmoat.com/developer/docs/errors#prompt_rejected) | The prompt failed the safety check. Nothing was charged. `field` names the field. |
| 502 | [`provider_error`](https://developer.vidmoat.com/developer/docs/errors#provider_error) | The generation provider failed. The charge is refunded. |

## Request examples

```bash curl
curl -X POST https://api.vidmoat.com/v1/ai/images \
  -H "Authorization: Bearer $VIDMOAT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"prompt":"a lighthouse in fog, cinematic"}'
```

```js Node
const res = await fetch('https://api.vidmoat.com/v1/ai/images', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.VIDMOAT_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    prompt: 'a lighthouse in fog, cinematic',
  }),
});
const data = await res.json();
if (!res.ok) throw new Error(data.error?.message ?? `HTTP ${res.status}`);
console.log(data);
```

```python Python
import os
import requests

res = requests.post(
    "https://api.vidmoat.com/v1/ai/images",
    headers={"Authorization": f"Bearer {os.environ['VIDMOAT_KEY']}"},
    json={
      "prompt": "a lighthouse in fog, cinematic",
    },
    timeout=60,
)
res.raise_for_status()
print(res.json())
```

## Example response

```json
{
  "url": "https://api.vidmoat.com/uploads/ai-image-abc.jpg",
  "route": { "provider": "grok", "model": "grok-imagine-image-quality", "credits": 60, "maxCredits": 256, "reason": "…", "policy": "2026-09-20.2" },
  "credits": { "charged": 60, "remaining": 4440 },
  "hint": "Use `url` as an addClip `src` with type: \"image\"."
}
```

---

Source: https://developer.vidmoat.com/developer/docs/api/generation/create-image
Previous: [Generate speech](https://developer.vidmoat.com/developer/docs/api/generation/create-speech.md)
Next: [Generate a sticker](https://developer.vidmoat.com/developer/docs/api/generation/create-sticker.md)
All documentation: https://developer.vidmoat.com/llms-full.txt
