{"openapi":"3.1.0","info":{"title":"GPT Image 2 Open API","version":"1.0.0","summary":"Generate GPT Image 2 images and inspect image tasks.","description":"Open API v1 exposes image generation, image task lookup, and credit balance lookup for paid accounts. Create a task with POST /api/open/v1/images/generations, poll it with GET /api/open/v1/images/generations/{id}, and review API-created image tasks in /activity/ai-tasks/api-logs. API tasks are stored in ai_task with source=api.","contact":{"name":"GPT Image 2 Support","email":"support@gpt-image-prompt.com"}},"jsonSchemaDialect":"https://json-schema.org/draft/2020-12/schema","servers":[{"url":"/","description":"Current host"}],"tags":[{"name":"Images","description":"Create and inspect GPT Image 2 generation tasks."},{"name":"Credits","description":"Inspect the credit balance for the API key owner."}],"security":[{"bearerAuth":[]}],"paths":{"/api/open/v1/images/generations":{"post":{"tags":["Images"],"operationId":"createImageGeneration","summary":"Create an image generation task","description":"Creates one GPT Image 2 image generation task. Send Authorization: Bearer sk-gip-... and a JSON body with a prompt, optional public reference image URLs, aspect_ratio, resolution, and visibility. The response returns the local task id immediately; use GET /api/open/v1/images/generations/{id} to check status until success or failure. Open API access requires a paid account, active IP block rules can reject generation before credits are consumed, and successful tasks appear in /activity/ai-tasks/api-logs.","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateImageGenerationRequest"},"examples":{"textToImage":{"summary":"Text to image","value":{"prompt":"A simple red square app icon, flat vector style, no text","aspect_ratio":"1:1","resolution":"1k","visibility":"public"}},"imageReference":{"summary":"Image reference URL","value":{"prompt":"Turn this product reference into a cinematic social media poster.","images":["https://example.com/reference.png"],"aspect_ratio":"1:1","resolution":"1k","visibility":"public"}}}}}},"responses":{"200":{"description":"Image generation task created.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ImageGenerationResponse"}}}},"400":{"$ref":"#/components/responses/ValidationError"},"401":{"$ref":"#/components/responses/UnauthorizedError"},"402":{"$ref":"#/components/responses/InsufficientCreditsError"},"403":{"$ref":"#/components/responses/ForbiddenError"},"500":{"$ref":"#/components/responses/InternalServerError"},"502":{"$ref":"#/components/responses/ProviderError"}}}},"/api/open/v1/images/generations/{id}":{"get":{"tags":["Images"],"operationId":"getImageGeneration","summary":"Get an image generation task","description":"Returns one image generation task owned by the same paid user as the API key. Pending or processing tasks may be refreshed from the upstream provider before returning. API-created image tasks can also be viewed in /activity/ai-tasks/api-logs.","parameters":[{"name":"id","in":"path","required":true,"description":"The image generation task id.","schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"Image generation task found.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ImageGenerationResponse"}}}},"401":{"$ref":"#/components/responses/UnauthorizedError"},"403":{"$ref":"#/components/responses/ForbiddenError"},"404":{"$ref":"#/components/responses/NotFoundError"},"500":{"$ref":"#/components/responses/InternalServerError"}}}},"/api/open/v1/credits":{"get":{"tags":["Credits"],"operationId":"getCredits","summary":"Get remaining credits","description":"Returns the current remaining credits for the paid user that owns the API key.","responses":{"200":{"description":"Credit balance returned.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreditsResponse"}}}},"401":{"$ref":"#/components/responses/UnauthorizedError"},"403":{"$ref":"#/components/responses/ForbiddenError"},"500":{"$ref":"#/components/responses/InternalServerError"}}}}},"components":{"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"sk-gip","description":"Use Authorization: Bearer sk-gip-... . Query parameters and custom API key headers are not accepted."}},"schemas":{"ApiEnvelope":{"type":"object","required":["code","message"],"properties":{"code":{"type":"integer","description":"0 for success, -1 for errors.","examples":[0]},"message":{"type":"string","examples":["ok"]}}},"ErrorResponse":{"allOf":[{"$ref":"#/components/schemas/ApiEnvelope"},{"type":"object","required":["error"],"properties":{"code":{"type":"integer","const":-1},"error":{"type":"string","examples":["invalid_api_key"]},"message":{"type":"string","examples":["Invalid API key"]}}}]},"CreateImageGenerationRequest":{"type":"object","additionalProperties":false,"required":["prompt"],"properties":{"prompt":{"type":"string","minLength":1,"maxLength":10000,"description":"Image generation prompt."},"images":{"type":"array","maxItems":4,"description":"Publicly reachable reference image URLs. Local file upload is not supported in v1.","items":{"type":"string","format":"uri","maxLength":2048},"default":[]},"aspect_ratio":{"$ref":"#/components/schemas/ImageAspectRatio"},"resolution":{"$ref":"#/components/schemas/ImageResolution"},"visibility":{"$ref":"#/components/schemas/ImageVisibility"}}},"ImageAspectRatio":{"type":"string","enum":["auto","1:1","16:9","9:16","4:3","3:4","3:2","2:3","5:4","4:5","2:1","1:2","21:9","9:21"],"default":"auto"},"ImageResolution":{"type":"string","enum":["1k","2k","4k"],"default":"1k","description":"1k costs 2 credits. 2k costs 4 credits and requires a paid account. 4k costs 6 credits, requires a paid account, and only supports selected aspect ratios."},"ImageVisibility":{"type":"string","enum":["public","private"],"default":"public","description":"Private image generation requires a paid account. Public successful tasks can be shared at /images/{id}."},"ImageGenerationStatus":{"type":"string","enum":["pending","processing","success","failed","canceled"]},"ImageGenerationTask":{"type":"object","required":["id","status","provider","model","source","cost_credits","visibility"],"properties":{"id":{"type":"string","format":"uuid"},"status":{"$ref":"#/components/schemas/ImageGenerationStatus"},"provider":{"type":"string","examples":["apimart"]},"model":{"type":"string","examples":["gpt-image-2"]},"prompt":{"type":["string","null"]},"options":{"type":["object","null"],"additionalProperties":true},"task_info":{"type":["object","null"],"additionalProperties":true},"task_id":{"type":["string","null"],"description":"Upstream provider task id, when available."},"task_result":{"type":["object","null"],"additionalProperties":true},"cost_credits":{"type":"integer","minimum":0},"visibility":{"$ref":"#/components/schemas/ImageVisibility"},"source":{"type":"string","enum":["web","api"]},"created_at":{"type":["string","null"],"format":"date-time"},"updated_at":{"type":["string","null"],"format":"date-time"}}},"ImageGenerationResponse":{"allOf":[{"$ref":"#/components/schemas/ApiEnvelope"},{"type":"object","required":["data"],"properties":{"data":{"$ref":"#/components/schemas/ImageGenerationTask"}}}]},"CreditsResponse":{"allOf":[{"$ref":"#/components/schemas/ApiEnvelope"},{"type":"object","required":["data"],"properties":{"data":{"type":"object","required":["remaining_credits"],"properties":{"remaining_credits":{"type":"integer","minimum":0}}}}}]}},"responses":{"ValidationError":{"description":"Invalid request body or parameter.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"},"examples":{"invalidRequest":{"value":{"code":-1,"error":"invalid_request","message":"prompt is required"}}}}}},"UnauthorizedError":{"description":"Missing, invalid, deleted, or expired API key.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"},"examples":{"invalidApiKey":{"value":{"code":-1,"error":"invalid_api_key","message":"Invalid API key"}}}}}},"ForbiddenError":{"description":"The API key lacks the required scope, the account lacks paid-only capability, or the request IP is blocked from image generation.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"},"examples":{"paidAccountRequired":{"value":{"code":-1,"error":"paid_account_required","message":"Open API access requires a paid account."}},"ipBlocked":{"value":{"code":-1,"error":"ip_blocked","message":"Your IP is blocked from image generation."}}}}}},"InsufficientCreditsError":{"description":"The key owner does not have enough credits.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"},"examples":{"insufficientCredits":{"value":{"code":-1,"error":"insufficient_credits","message":"insufficient credits for 1K generation, 0 < 2"}}}}}},"NotFoundError":{"description":"The image generation task does not exist or does not belong to the key owner.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"InternalServerError":{"description":"Unexpected server error.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"ProviderError":{"description":"The upstream image provider failed. The task is marked failed and refund logic is triggered.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}}