curl, Python requests, and JavaScript fetch, and most Python examples also have a Python (OpenAI SDK) tab.
Any HTTP client
Send JSON (ormultipart/form-data for file uploads) to https://external.api.recraft.ai/v1 with a Bearer token:
Synchronous requests
Every request is synchronous: the connection stays open until the images are ready, and the response carries them (as URLs, Base64, or bytes). There are no job IDs to poll and no webhooks.- Set your HTTP client’s timeout explicitly instead of relying on its default, and keep it long enough for the slowest model you call.
- To generate many images, send requests in parallel within the rate limits, or ask for up to 6 images in one request with
n.
OpenAI Python library
The OpenAI Python library is compatible with the Recraft API. Point it at the Recraft base URL:-
Recraft-specific parameters go in
extra_body. The library passesprompt,model,n,size, andresponse_formatnatively. Everything else (style_id,style_reference_urls,style_match,controls,image_format,negative_prompt,text_layout, …) must go throughextra_body, or the library rejects it: -
Endpoints outside the OpenAI API (styles, vectorize, upscale, inpaint, and others) are called with
client.post: -
multipartresponses are not supported. The library reads JSON only, so useresponse_formaturlorb64_jsonwith it, and a plain HTTP client formultipart. - Some OpenAI parameters don’t apply. Parameters without a Recraft meaning are ignored or may be interpreted differently. Check the model page for what each model accepts.