Skip to main content
POST
/
v1
/
ai-image-generator
Python
from magic_hour import Client
from os import getenv

client = Client(token=getenv("API_TOKEN"))
res = client.v1.ai_image_generator.generate(
    image_count=1,
    style={
        "prompt": "Cool image",
        "tool": "ai-anime-generator",
    },
    aspect_ratio="1:1",
    model="default",
    name="My Ai Image image",
    resolution="auto",
    wait_for_completion=True,
    download_outputs=True,
    download_directory="outputs"
)
{
  "id": "cuid-example",
  "credits_charged": 5
}

Authorizations

Authorization
string
header
required

Bearer authentication header of the form Bearer <api_key>, where <api_key> is your API key. To get your API key, go to Developer Hub and click "Create new API Key".

Body

application/json

Body

image_count
integer
required

Number of images to generate. Maximum varies by model.

Required range: 1 <= x <= 16
Example:

1

style
object
required

The art style to use for image generation.

name
string
default:Ai Image - dateTime

Give your image a custom name for easy identification.

Example:

"My Ai Image image"

model
enum<string>

The AI model to use for image generation. Each model has different capabilities and costs.

Models:

  • default - Use the model we recommend, which will change over time. This is recommended unless you need a specific model. This is the default behavior.
  • flux-schnell - 5 credits/image
    • Supported resolutions: auto
    • Available for tiers: free, creator, pro, business
    • Image count allowed: 1, 2, 3, 4
  • z-image-turbo - 5 credits/image
    • Supported resolutions: auto, 2k
    • Available for tiers: free, creator, pro, business
    • Image count allowed: 1, 2, 3, 4
  • seedream - 30 credits/image
    • Supported resolutions: auto, 2k, 4k
    • Available for tiers: free, creator, pro, business
    • Image count allowed: 1, 2, 3, 4
  • nano-banana-pro - 150 credits/image
    • Supported resolutions: auto
    • Available for tiers: creator, pro, business
    • Image count allowed: 1, 4, 9, 16
Available options:
default,
flux-schnell,
z-image-turbo,
seedream,
nano-banana-pro
Example:

"default"

aspect_ratio
enum<string>

The aspect ratio of the output image(s). If not specified, defaults to 1:1 (square).

Available options:
1:1,
16:9,
9:16
Example:

"1:1"

resolution
enum<string>
default:auto

Maximum resolution for the generated image.

Options:

  • auto - Automatic resolution (all tiers, default)
  • 2k - Up to 2048px (requires Pro or Business tier)
  • 4k - Up to 4096px (requires Business tier)

Note: Resolution availability depends on the model and your subscription tier. See model field for which resolutions each model supports. Defaults to auto if not specified.

Available options:
auto,
2k,
4k
Example:

"auto"

Response

Success

Success

id
string
required

Unique ID of the image. Use it with the Get image Project API to fetch status and downloads.

Example:

"cuid-example"

credits_charged
integer
required

The amount of credits deducted from your account to generate the image. We charge credits right when the request is made.

If an error occurred while generating the image(s), credits will be refunded and this field will be updated to include the refund.

Example:

5