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:
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.