> For clean Markdown of any page, append .md to the page URL. > For a complete documentation index, see https://developer.ideogram.ai/v1/api-reference/describe-prompts/magic-prompt-v4/llms.txt. > For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://developer.ideogram.ai/_mcp/server. # Generate a Magic Prompt with Ideogram 4.0 POST https://api.ideogram.ai/v1/ideogram-v4/magic-prompt Content-Type: application/json Transforms a basic prompt into an enhanced Ideogram 4.0 magic prompt. The magic prompt model version is fixed; callers cannot select it. When `aspect_ratio` is `AUTO` (the default), the model selects the most suitable aspect ratio for the prompt and returns it in the response. Reference: https://developer.ideogram.ai/v1/api-reference/describe-prompts/magic-prompt-v4 ## Authentication - `Api-Key` header (required) — API key for access control. Use in the header with the name \"Api-Key\" ## Request ### Body (application/json) This endpoint expects a MagicPromptV4Request. - `text_prompt` (string, required) — The natural-language prompt to enhance into an Ideogram 4.0 magic prompt. Named `text_prompt` to match the Ideogram 4.0 generate request surface. - `aspect_ratio` (enum, optional, default: AUTO) — Target aspect ratio. Defaults to `AUTO`, which lets the model select the most suitable ratio and return it in the response. - Allowed values: `AUTO`, `1x4`, `1x3`, `1x2`, `9x16`, `10x16`, `2x3`, `3x4`, `4x5`, `1x1`, `5x4`, `4x3`, `3x2`, `16x10`, `16x9`, `2x1`, `3x1`, `4x1` ## Response ### 200 Magic prompt generated successfully. - `json_prompt` (V4JsonPrompt, required) — The enhanced prompt as an Ideogram 4.0 structured JSON prompt. This conforms to the same contract as `json_prompt` on `/v1/ideogram-v4/generate`, so it can be passed straight back to that endpoint. - `aspect_ratio` (enum, required, default: AUTO) — The resolved aspect ratio. When the request used `AUTO`, this is the ratio the model selected; otherwise it echoes the request. - Allowed values: `AUTO`, `1x4`, `1x3`, `1x2`, `9x16`, `10x16`, `2x3`, `3x4`, `4x5`, `1x1`, `5x4`, `4x3`, `3x2`, `16x10`, `16x9`, `2x1`, `3x1`, `4x1` ## Errors ### 400 Bad Request Error Invalid input provided. - `any` ### 401 Unauthorized Error Not authorized to generate magic prompts. - `any` ### 429 Too Many Requests Error Too many requests. - `any` ### 500 Internal Server Error Internal server error. - `any` ## Types ### V4JsonPrompt Structured prompt for Ideogram 4.0 generation. When `json_prompt` is supplied, magic-prompt is disabled and the diffusion model consumes the JSON contract directly. Mutually exclusive with `text_prompt` and the legacy `prompt` field. - `high_level_description` (string, required) — One- or two-sentence overall description of the desired image. - `compositional_deconstruction` (V4CompositionalDeconstruction, required) — The compositional breakdown of a V4 prompt — background plus an ordered list of elements. - `style_description` (V4StyleDescription, optional) — Optional style description supplied alongside a V4 JSON prompt. ### V4CompositionalDeconstruction The compositional breakdown of a V4 prompt — background plus an ordered list of elements. - `background` (string, required) — Description of the background of the scene. - `elements` (list of V4PromptElement, required) — Ordered list of elements (objects and text) composing the scene. ### V4StyleDescription Optional style description supplied alongside a V4 JSON prompt. - `aesthetics` (string, optional) — Aesthetic notes (mood, vibe, references). - `art_style` (string, optional) — Optional art-style hint (e.g., illustration, oil painting). - `lighting` (string, optional) — Lighting description. - `medium` (string, optional) — Medium description (e.g., photograph, digital art). - `photo` (string, optional) — Optional photographic style notes (e.g., lens, film stock). - `color_palette` (list of string, optional) — Optional list of hex color strings (e.g. "#FFD700") that bias the Ideogram 4.0 output toward this palette. Applied as a soft color bias, not an exact per-pixel lock. ### V4PromptElement A single element in the V4 prompt's compositional deconstruction. Discriminated by the `type` field. - `type`: `obj` (V4ObjPromptElement) - `desc` (string, required) — Description of the object element. - `bbox` (list of integer, optional) — Bounding box for an element, expressed as four integers in `[0, 1000]` with `[y_min, x_min, y_max, x_max]` semantics (row-first). Values are normalized so the canvas is `1000 x 1000` regardless of the final resolution. - `color_palette` (list of string, optional) — Optional list of hex color strings (e.g. "#FFD700") that bias the Ideogram 4.0 output toward this palette. Applied as a soft color bias, not an exact per-pixel lock. - `type`: `text` (V4TextPromptElement) - `desc` (string, required) — Description of the text element (style, role, placement notes). - `text` (string, required) — The literal text to render in the image. - `bbox` (list of integer, optional) — Bounding box for an element, expressed as four integers in `[0, 1000]` with `[y_min, x_min, y_max, x_max]` semantics (row-first). Values are normalized so the canvas is `1000 x 1000` regardless of the final resolution. - `color_palette` (list of string, optional) — Optional list of hex color strings (e.g. "#FFD700") that bias the Ideogram 4.0 output toward this palette. Applied as a soft color bias, not an exact per-pixel lock. ## Examples **Request** ```json { "text_prompt": "A photo of a cat", "aspect_ratio": "AUTO" } ``` **Response** ```json { "json_prompt": { "high_level_description": "A photorealistic ginger cat perched on a vintage wooden chair by a sunlit window.", "compositional_deconstruction": { "background": "A dim room with a bright window casting warm light.", "elements": [ { "type": "obj", "desc": "ginger cat with green eyes sitting upright on a vintage wooden chair" } ] }, "style_description": { "aesthetics": "warm, cozy, nostalgic", "lighting": "soft natural window light", "medium": "photograph" } }, "aspect_ratio": "1x1" } ``` **SDK Code** ```python import requests url = "https://api.ideogram.ai/v1/ideogram-v4/magic-prompt" payload = { "text_prompt": "A photo of a cat", "aspect_ratio": "AUTO" } headers = { "Api-Key": "", "Content-Type": "application/json" } response = requests.post(url, json=payload, headers=headers) print(response.json()) ``` ```javascript const url = 'https://api.ideogram.ai/v1/ideogram-v4/magic-prompt'; const options = { method: 'POST', headers: {'Api-Key': '', 'Content-Type': 'application/json'}, body: '{"text_prompt":"A photo of a cat","aspect_ratio":"AUTO"}' }; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` ```go package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://api.ideogram.ai/v1/ideogram-v4/magic-prompt" payload := strings.NewReader("{\n \"text_prompt\": \"A photo of a cat\",\n \"aspect_ratio\": \"AUTO\"\n}") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("Api-Key", "") req.Header.Add("Content-Type", "application/json") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` ```ruby require 'uri' require 'net/http' url = URI("https://api.ideogram.ai/v1/ideogram-v4/magic-prompt") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Post.new(url) request["Api-Key"] = '' request["Content-Type"] = 'application/json' request.body = "{\n \"text_prompt\": \"A photo of a cat\",\n \"aspect_ratio\": \"AUTO\"\n}" response = http.request(request) puts response.read_body ``` ```java import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.post("https://api.ideogram.ai/v1/ideogram-v4/magic-prompt") .header("Api-Key", "") .header("Content-Type", "application/json") .body("{\n \"text_prompt\": \"A photo of a cat\",\n \"aspect_ratio\": \"AUTO\"\n}") .asString(); ``` ```php request('POST', 'https://api.ideogram.ai/v1/ideogram-v4/magic-prompt', [ 'body' => '{ "text_prompt": "A photo of a cat", "aspect_ratio": "AUTO" }', 'headers' => [ 'Api-Key' => '', 'Content-Type' => 'application/json', ], ]); echo $response->getBody(); ``` ```csharp using RestSharp; var client = new RestClient("https://api.ideogram.ai/v1/ideogram-v4/magic-prompt"); var request = new RestRequest(Method.POST); request.AddHeader("Api-Key", ""); request.AddHeader("Content-Type", "application/json"); request.AddParameter("application/json", "{\n \"text_prompt\": \"A photo of a cat\",\n \"aspect_ratio\": \"AUTO\"\n}", ParameterType.RequestBody); IRestResponse response = client.Execute(request); ``` ```swift import Foundation let headers = [ "Api-Key": "", "Content-Type": "application/json" ] let parameters = [ "text_prompt": "A photo of a cat", "aspect_ratio": "AUTO" ] as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest(url: NSURL(string: "https://api.ideogram.ai/v1/ideogram-v4/magic-prompt")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "POST" request.allHTTPHeaderFields = headers request.httpBody = postData as Data let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ```