openapi: 3.2.0 info: title: Pictomancer.ai Gateway Optimize Generated API version: 0.1.0 tags: - name: Optimize Generated paths: /v1/optimize_generated: post: summary: Optimize an AI-generated image for the web description: 'The step after image generation. gpt-image, DALL-E, Flux, Midjourney and Stable Diffusion hand back 2-8 MB PNGs; this returns the same picture as a web-ready webp (default), avif, jpeg or png, metadata stripped, transparency kept on webp/avif/png. Optional max_dimension caps the longest side (never upscales); optional q or quality_target (smallest file with SSIM >= target, flat surcharge) control quality. Same price as convert. If the result is not smaller than the input it is still returned but free (X-Pig-Billed: 0). X-Pictomancer-Bytes-Before/-After/-Saved-Percent report the saving. The input''s C2PA manifest, if any, is reported in X-Pictomancer-C2PA-Input but is not carried over: re-encoding invalidates it.' operationId: optimize_generated_image requestBody: content: application/json: schema: $ref: '#/components/schemas/OptimizeGeneratedRequest' required: true responses: '200': description: Processed image binary content: application/json: schema: {} image/jpeg: schema: type: string format: binary image/png: schema: type: string format: binary image/webp: schema: type: string format: binary '422': description: Validation Error content: application/json: schema: $ref: '#/components/schemas/HTTPValidationError' tags: - Optimize Generated components: schemas: OptimizeGeneratedRequest: properties: delivery: oneOf: - $ref: '#/components/schemas/InlineDelivery' - $ref: '#/components/schemas/PutUrlDelivery' - $ref: '#/components/schemas/CallbackDelivery' title: Delivery discriminator: propertyName: mode mapping: callback_url: '#/components/schemas/CallbackDelivery' inline: '#/components/schemas/InlineDelivery' put_url: '#/components/schemas/PutUrlDelivery' source: type: string title: Source description: 'Image source: a public URL (https://...) or a base64-encoded string (optionally as a data URI like data:image/png;base64,...).' format: type: string title: Format description: 'Output format: webp (default), avif, jpeg or png. webp, avif and png keep transparency; jpeg flattens it.' default: webp q: anyOf: - type: integer - type: 'null' title: Q description: Quality (1-100). Maps to libvips Q parameter. Omit to use the encoder default; or set quality_target instead. quality_target: anyOf: - type: number - type: 'null' title: Quality Target description: 'Target SSIM (0-1]: the worker searches for the smallest file that still scores at least this. Alternative to q; mutually exclusive with it. Carries a flat surcharge for the extra encodes.' max_dimension: anyOf: - type: integer - type: 'null' title: Max Dimension description: Cap on the longest side in pixels. Larger images are scaled down to fit, aspect ratio preserved; smaller images are never upscaled. strip: type: boolean title: Strip description: 'Strip metadata. Defaults to true: generated images carry no EXIF worth keeping. Metadata includes any C2PA manifest, which would be invalid after re-encoding anyway.' default: true additionalProperties: true type: object required: - source title: OptimizeGeneratedRequest PutUrlDelivery: properties: mode: type: string const: put_url title: Mode put_url: type: string maxLength: 2083 minLength: 1 format: uri title: Put Url description: Customer-signed presigned PUT URL where the optimized bytes will be written. Must be https://. Cloud credentials never reach our infrastructure; only the URL itself is used and discarded after the request. headers: anyOf: - additionalProperties: type: string type: object - type: 'null' title: Headers description: Optional storage headers to include on the PUT call (Content-Type, Cache-Control, x-amz-acl, etc.). Whitelisted at SSRF layer. additionalProperties: false type: object required: - mode - put_url title: PutUrlDelivery HTTPValidationError: properties: detail: items: $ref: '#/components/schemas/ValidationError' type: array title: Detail type: object title: HTTPValidationError ValidationError: properties: loc: items: anyOf: - type: string - type: integer type: array title: Location msg: type: string title: Message type: type: string title: Error Type input: title: Input ctx: type: object title: Context type: object required: - loc - msg - type title: ValidationError InlineDelivery: properties: mode: type: string const: inline title: Mode default: inline additionalProperties: false type: object title: InlineDelivery CallbackDelivery: properties: mode: type: string const: callback_url title: Mode callback_url: type: string maxLength: 2083 minLength: 1 format: uri title: Callback Url description: Customer endpoint where the optimized bytes will be POSTed. Must be https://. For async/large jobs. We send an X-Pig-Sha256 header of the body so the receiver can verify integrity. No credentials are stored on our side; secure the endpoint with a token in the URL itself. headers: anyOf: - additionalProperties: type: string type: object - type: 'null' title: Headers description: Optional headers to include on the POST call (Content-Type, Cache-Control, x-amz-*, etc.). Whitelisted at SSRF layer. secret: anyOf: - type: string - type: 'null' title: Secret description: 'Optional HMAC secret. When set, we sign the POST body with HMAC-SHA256 and send ''X-Pig-Signature: sha256=''. Used per request and never stored. Recompute the HMAC on your endpoint to authenticate the callback (constant-time compare).' additionalProperties: false type: object required: - mode - callback_url title: CallbackDelivery