from magic_hour import Client
from os import getenv
client = Client(token=getenv("MAGIC_HOUR_API_KEY"))
res = client.v1.ai_image_editor.generate(
assets={"image_file_paths": ["api-assets/id/1234.png", "api-assets/id/1235.png"]},
style={"prompt": "Give me sunglasses"},
aspect_ratio="1:1",
image_count=1.0,
model="flux-2-klein",
name="My Ai Image Editor image",
resolution="640px",
wait_for_completion=True,
download_outputs=True,
download_directory="."
)import { Client } from "magic-hour";
const client = new Client({ token: process.env["MAGIC_HOUR_API_KEY"] });
const res = await client.v1.aiImageEditor.generate(
{
assets: { imageFilePaths: ["/path/to/1234.png", "/path/to/1235.png"] },
name: "Ai Image Editor image",
style: { prompt: "Give me sunglasses" },
},
{
waitForCompletion: true,
downloadOutputs: true,
downloadDirectory: ".",
},
);package main
import (
os "os"
sdk "github.com/magichourhq/magic-hour-go/client"
nullable "github.com/magichourhq/magic-hour-go/nullable"
ai_image_editor "github.com/magichourhq/magic-hour-go/resources/v1/ai_image_editor"
types "github.com/magichourhq/magic-hour-go/types"
)
func main() {
client := sdk.NewClient(
sdk.WithBearerAuth(os.Getenv("MAGIC_HOUR_API_KEY")),
)
res, err := client.V1.AiImageEditor.Create(ai_image_editor.CreateRequest{
AspectRatio: nullable.NewValue(types.V1AiImageEditorCreateBodyAspectRatioEnum11),
Assets: types.V1AiImageEditorCreateBodyAssets{
ImageFilePaths: nullable.NewValue([]string{
"api-assets/id/1234.png",
"api-assets/id/1235.png",
}),
},
ImageCount: nullable.NewValue(1.0),
Model: nullable.NewValue(types.V1AiImageEditorCreateBodyModelEnumFlux2Klein),
Name: nullable.NewValue("My Ai Image Editor image"),
Resolution: nullable.NewValue(types.V1AiImageEditorCreateBodyResolutionEnum640px),
Style: types.V1AiImageEditorCreateBodyStyle{
Prompt: "Give me sunglasses",
},
})
}let client = magic_hour::Client::default()
.with_bearer_auth(&std::env::var("MAGIC_HOUR_API_KEY").unwrap());
let res = client
.v1()
.ai_image_editor()
.create(magic_hour::resources::v1::ai_image_editor::CreateRequest {
aspect_ratio: Some(
magic_hour::models::V1AiImageEditorCreateBodyAspectRatioEnum::Enum11,
),
assets: magic_hour::models::V1AiImageEditorCreateBodyAssets {
image_file_paths: Some(
vec![
"api-assets/id/1234.png".to_string(), "api-assets/id/1235.png"
.to_string()
],
),
..Default::default()
},
image_count: Some(1.0),
model: Some(
magic_hour::models::V1AiImageEditorCreateBodyModelEnum::Flux2Klein,
),
name: Some("My Ai Image Editor image".to_string()),
resolution: Some(
magic_hour::models::V1AiImageEditorCreateBodyResolutionEnum::Enum640px,
),
style: magic_hour::models::V1AiImageEditorCreateBodyStyle {
prompt: "Give me sunglasses".to_string(),
..Default::default()
},
})
.await;curl --request POST \
--url https://api.magichour.ai/v1/ai-image-editor \
--header 'accept: application/json' \
--header "authorization: Bearer $MAGIC_HOUR_API_KEY" \
--header 'content-type: application/json' \
--data '
{
"name": "My Ai Image Editor image",
"image_count": 1,
"model": "flux-2-klein",
"aspect_ratio": "1:1",
"resolution": "640px",
"style": {
"prompt": "Give me sunglasses"
},
"assets": {
"image_file_paths": [
"api-assets/id/1234.png",
"api-assets/id/1235.png"
]
}
}
'<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.magichour.ai/v1/ai-image-editor",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'name' => 'My Ai Image Editor image',
'image_count' => 1,
'model' => 'flux-2-klein',
'aspect_ratio' => '1:1',
'resolution' => '640px',
'style' => [
'prompt' => 'Give me sunglasses'
],
'assets' => [
'image_file_paths' => [
'api-assets/id/1234.png',
'api-assets/id/1235.png'
]
]
]),
CURLOPT_HTTPHEADER => [
"accept: application/json",
"authorization: Bearer <token>",
"content-type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}HttpResponse<String> response = Unirest.post("https://api.magichour.ai/v1/ai-image-editor")
.header("accept", "application/json")
.header("content-type", "application/json")
.header("authorization", "Bearer <token>")
.body("{\"name\":\"My Ai Image Editor image\",\"image_count\":1,\"model\":\"flux-2-klein\",\"aspect_ratio\":\"1:1\",\"resolution\":\"640px\",\"style\":{\"prompt\":\"Give me sunglasses\"},\"assets\":{\"image_file_paths\":[\"api-assets/id/1234.png\",\"api-assets/id/1235.png\"]}}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.magichour.ai/v1/ai-image-editor")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"style\": {\n \"prompt\": \"Give me sunglasses\"\n },\n \"assets\": {\n \"image_file_paths\": [\n \"api-assets/id/1234.png\",\n \"api-assets/id/1235.png\"\n ]\n },\n \"name\": \"My Ai Image Editor image\",\n \"image_count\": 1,\n \"model\": \"flux-2-klein\",\n \"aspect_ratio\": \"1:1\",\n \"resolution\": \"640px\"\n}"
response = http.request(request)
puts response.read_body{
"id": "cuid-example",
"credits_charged": 5
}{
"code": "invalid_request",
"message": "<string>"
}{
"code": "unauthorized",
"message": "<string>"
}{
"code": "insufficient_credits",
"message": "<string>",
"credit_shortfall": 123,
"credits_available": 123,
"credits_required": 123,
"next_action": {
"type": "check_balance",
"reason": "auto_reload_pending"
}
}{
"code": "not_found",
"message": "<string>"
}{
"code": "unprocessable_entity",
"message": "<string>"
}{
"code": "internal_server_error",
"message": "<string>"
}AI Image Editor
Edit images with AI.
from magic_hour import Client
from os import getenv
client = Client(token=getenv("MAGIC_HOUR_API_KEY"))
res = client.v1.ai_image_editor.generate(
assets={"image_file_paths": ["api-assets/id/1234.png", "api-assets/id/1235.png"]},
style={"prompt": "Give me sunglasses"},
aspect_ratio="1:1",
image_count=1.0,
model="flux-2-klein",
name="My Ai Image Editor image",
resolution="640px",
wait_for_completion=True,
download_outputs=True,
download_directory="."
)import { Client } from "magic-hour";
const client = new Client({ token: process.env["MAGIC_HOUR_API_KEY"] });
const res = await client.v1.aiImageEditor.generate(
{
assets: { imageFilePaths: ["/path/to/1234.png", "/path/to/1235.png"] },
name: "Ai Image Editor image",
style: { prompt: "Give me sunglasses" },
},
{
waitForCompletion: true,
downloadOutputs: true,
downloadDirectory: ".",
},
);package main
import (
os "os"
sdk "github.com/magichourhq/magic-hour-go/client"
nullable "github.com/magichourhq/magic-hour-go/nullable"
ai_image_editor "github.com/magichourhq/magic-hour-go/resources/v1/ai_image_editor"
types "github.com/magichourhq/magic-hour-go/types"
)
func main() {
client := sdk.NewClient(
sdk.WithBearerAuth(os.Getenv("MAGIC_HOUR_API_KEY")),
)
res, err := client.V1.AiImageEditor.Create(ai_image_editor.CreateRequest{
AspectRatio: nullable.NewValue(types.V1AiImageEditorCreateBodyAspectRatioEnum11),
Assets: types.V1AiImageEditorCreateBodyAssets{
ImageFilePaths: nullable.NewValue([]string{
"api-assets/id/1234.png",
"api-assets/id/1235.png",
}),
},
ImageCount: nullable.NewValue(1.0),
Model: nullable.NewValue(types.V1AiImageEditorCreateBodyModelEnumFlux2Klein),
Name: nullable.NewValue("My Ai Image Editor image"),
Resolution: nullable.NewValue(types.V1AiImageEditorCreateBodyResolutionEnum640px),
Style: types.V1AiImageEditorCreateBodyStyle{
Prompt: "Give me sunglasses",
},
})
}let client = magic_hour::Client::default()
.with_bearer_auth(&std::env::var("MAGIC_HOUR_API_KEY").unwrap());
let res = client
.v1()
.ai_image_editor()
.create(magic_hour::resources::v1::ai_image_editor::CreateRequest {
aspect_ratio: Some(
magic_hour::models::V1AiImageEditorCreateBodyAspectRatioEnum::Enum11,
),
assets: magic_hour::models::V1AiImageEditorCreateBodyAssets {
image_file_paths: Some(
vec![
"api-assets/id/1234.png".to_string(), "api-assets/id/1235.png"
.to_string()
],
),
..Default::default()
},
image_count: Some(1.0),
model: Some(
magic_hour::models::V1AiImageEditorCreateBodyModelEnum::Flux2Klein,
),
name: Some("My Ai Image Editor image".to_string()),
resolution: Some(
magic_hour::models::V1AiImageEditorCreateBodyResolutionEnum::Enum640px,
),
style: magic_hour::models::V1AiImageEditorCreateBodyStyle {
prompt: "Give me sunglasses".to_string(),
..Default::default()
},
})
.await;curl --request POST \
--url https://api.magichour.ai/v1/ai-image-editor \
--header 'accept: application/json' \
--header "authorization: Bearer $MAGIC_HOUR_API_KEY" \
--header 'content-type: application/json' \
--data '
{
"name": "My Ai Image Editor image",
"image_count": 1,
"model": "flux-2-klein",
"aspect_ratio": "1:1",
"resolution": "640px",
"style": {
"prompt": "Give me sunglasses"
},
"assets": {
"image_file_paths": [
"api-assets/id/1234.png",
"api-assets/id/1235.png"
]
}
}
'<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.magichour.ai/v1/ai-image-editor",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'name' => 'My Ai Image Editor image',
'image_count' => 1,
'model' => 'flux-2-klein',
'aspect_ratio' => '1:1',
'resolution' => '640px',
'style' => [
'prompt' => 'Give me sunglasses'
],
'assets' => [
'image_file_paths' => [
'api-assets/id/1234.png',
'api-assets/id/1235.png'
]
]
]),
CURLOPT_HTTPHEADER => [
"accept: application/json",
"authorization: Bearer <token>",
"content-type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}HttpResponse<String> response = Unirest.post("https://api.magichour.ai/v1/ai-image-editor")
.header("accept", "application/json")
.header("content-type", "application/json")
.header("authorization", "Bearer <token>")
.body("{\"name\":\"My Ai Image Editor image\",\"image_count\":1,\"model\":\"flux-2-klein\",\"aspect_ratio\":\"1:1\",\"resolution\":\"640px\",\"style\":{\"prompt\":\"Give me sunglasses\"},\"assets\":{\"image_file_paths\":[\"api-assets/id/1234.png\",\"api-assets/id/1235.png\"]}}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.magichour.ai/v1/ai-image-editor")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"style\": {\n \"prompt\": \"Give me sunglasses\"\n },\n \"assets\": {\n \"image_file_paths\": [\n \"api-assets/id/1234.png\",\n \"api-assets/id/1235.png\"\n ]\n },\n \"name\": \"My Ai Image Editor image\",\n \"image_count\": 1,\n \"model\": \"flux-2-klein\",\n \"aspect_ratio\": \"1:1\",\n \"resolution\": \"640px\"\n}"
response = http.request(request)
puts response.read_body{
"id": "cuid-example",
"credits_charged": 5
}{
"code": "invalid_request",
"message": "<string>"
}{
"code": "unauthorized",
"message": "<string>"
}{
"code": "insufficient_credits",
"message": "<string>",
"credit_shortfall": 123,
"credits_available": 123,
"credits_required": 123,
"next_action": {
"type": "check_balance",
"reason": "auto_reload_pending"
}
}{
"code": "not_found",
"message": "<string>"
}{
"code": "unprocessable_entity",
"message": "<string>"
}{
"code": "internal_server_error",
"message": "<string>"
}Authorizations
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".
Headers
A unique string for this request, such as a UUID. Sending the same key again within 24 hours returns the original project instead of creating and charging for a new one. A key applies across all video, image, and audio endpoints on your account, so use a new key for every project.
"5f3c1b9e-8a41-4a0e-9d3e-2f6a1c7b9e10"
Body
Body
The AI model to use for image editing. 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-2-klein- from 5 credits/image- Supported resolutions: 640px, 1k, 2k
- Available for tiers: free, creator, pro, business
- Max additional input images: 5
flux-3-klein- from 5 credits/image- Supported resolutions: 640px, 1k, 2k
- Available for tiers: free, creator, pro, business
- Max additional input images: 1
gpt-image-2- from 50 credits/image- Supported resolutions: 640px, 1k, 2k, 4k
- Available for tiers: creator, pro, business
- Max additional input images: 9
gpt-image-2.5-flare- from 100 credits/image- Supported resolutions: 640px, 1k, 2k, 4k
- Available for tiers: creator, pro, business
- Max additional input images: 9
krea-2- from 10 credits/image- Supported resolutions: 640px, 1k
- Available for tiers: free, creator, pro, business
- Max additional input images: 1
nano-banana- from 50 credits/image- Supported resolutions: 640px, 1k
- Available for tiers: creator, pro, business
- Max additional input images: 9
nano-banana-2- from 100 credits/image- Supported resolutions: 640px, 1k, 2k, 4k
- Available for tiers: creator, pro, business
- Max additional input images: 9
nano-banana-2-lite- from 50 credits/image- Supported resolutions: 640px, 1k
- Available for tiers: creator, pro, business
- Max additional input images: 9
nano-banana-2.1- from 50 credits/image- Supported resolutions: 640px, 1k, 2k, 4k
- Available for tiers: creator, pro, business
- Max additional input images: 9
nano-banana-pro- from 150 credits/image- Supported resolutions: 1k, 2k, 4k
- Available for tiers: creator, pro, business
- Max additional input images: 9
qwen-edit- from 10 credits/image- Supported resolutions: 640px, 1k, 2k
- Available for tiers: free, creator, pro, business
- Max additional input images: 2
qwen-image-2.1- from 10 credits/image- Supported resolutions: 640px, 1k, 2k
- Available for tiers: free, creator, pro, business
- Max additional input images: 2
seedream-v4- from 40 credits/image- Supported resolutions: 640px, 1k, 2k, 4k
- Available for tiers: creator, pro, business
- Max additional input images: 9
seedream-v4.5- from 50 credits/image- Supported resolutions: 640px, 1k, 2k, 4k
- Available for tiers: creator, pro, business
- Max additional input images: 9
seedream-v5-flash- from 30 credits/image- Supported resolutions: 640px, 1k, 2k
- Available for tiers: creator, pro, business
- Max additional input images: 9
seedream-v5-pro- from 75 credits/image- Supported resolutions: 640px, 1k, 2k
- Available for tiers: creator, pro, business
- Max additional input images: 9
default, qwen-image-2.1, gpt-image-2, flux-2-klein, flux-3-klein, nano-banana-pro, seedream-v5-pro, seedream-v5-flash, seedream-v4.5, nano-banana-2.1, qwen-edit, nano-banana-2-lite, krea-2, gpt-image-2.5-flare, seedream-v4, nano-banana, nano-banana-2 "flux-2-klein"
Maximum resolution (longest edge) for the output image.
Options:
640px— up to 640px1k— up to 1024px2k— up to 2048px4k— up to 4096pxauto— Deprecated. Mapped server-side from your subscription tier to the best matching resolution the model supports
Per-model support:
flux-2-klein- 640px, 1k, 2kflux-3-klein- 640px, 1k, 2kgpt-image-2- 640px, 1k, 2k, 4kgpt-image-2.5-flare- 640px, 1k, 2k, 4kkrea-2- 640px, 1knano-banana- 640px, 1knano-banana-2- 640px, 1k, 2k, 4knano-banana-2-lite- 640px, 1knano-banana-2.1- 640px, 1k, 2k, 4knano-banana-pro- 1k, 2k, 4kqwen-edit- 640px, 1k, 2kqwen-image-2.1- 640px, 1k, 2kseedream-v4- 640px, 1k, 2k, 4kseedream-v4.5- 640px, 1k, 2k, 4kseedream-v5-flash- 640px, 1k, 2kseedream-v5-pro- 640px, 1k, 2k
Note: Resolution availability depends on the model and your subscription tier.
auto, 640px, 1k, 2k, 4k "640px"
Response
Success
Success
Unique ID of the image. Use it with the Get image Project API to fetch status and downloads.
"cuid-example"
Was this page helpful?