Skip to main content
How images are passed to the Recraft API and how generated images are returned.

Image inputs

Every endpoint that takes an image (or mask) as input accepts the request in two interchangeable formats:
  • multipart/form-data — upload the binary file directly using form fields (image, mask, file, …). This is convenient for local files.
  • application/json — pass the image by reference instead of uploading bytes. Each file field has a JSON counterpart that accepts a public URL or a data URL (a data:image/...;base64,... string).
The mapping between the multipart file fields and their JSON counterparts: All other parameters are identical between the two formats. Use JSON when your image is already hosted somewhere (just send the URL) or when a JSON body fits your client better; use multipart to upload local files directly.

Examples

Generate an image with a style reference passed as a file and as a URL:

multipart/form-data

application/json

Image results

Every endpoint that returns images takes the response_format parameter:
  • url (default) — a JSON response, every image carries a url to download it from.
  • b64_json — a JSON response, every image carries its bytes Base64-encoded in b64_json.
  • multipart — a multipart/form-data response. The response part carries the same JSON with an image_id per image, followed by one part per image with the raw bytes. The part is named by the image_id, which is also in its Content-ID header, and its Content-Type is the image media type (image/png, image/webp or image/svg+xml).
For the best latency use response_format: multipart.
Errors keep their JSON body and non-200 status with every response_format. The OpenAI Python library only reads JSON responses, so use url or b64_json with it and a plain HTTP client for multipart.

Examples

url

b64_json

multipart