https://www.recraft.ai/docs/api-reference/agents.md. Everything needed to write working code against the Recraft API is here.
Rules for writing code
- Use plain HTTP:
curl, Pythonrequests, or JavaScriptfetch. Do not use the OpenAI SDK unless asked; if you do, every non-OpenAI parameter must go inextra_body. - Read the token from the
RECRAFT_API_TOKENenvironment variable. Never hard-code it. - Always pass
modelexplicitly. Pick it from the model table below. - Only send parameters the chosen model supports (see the model table). Unsupported parameters are rejected or ignored.
- On a non-2xx response, print the status code and the response body (it explains the error), then stop. Errors keep a JSON body and a non-2xx status with every
response_format. - Image URLs in responses are temporary (about 24 hours). Download the files if they must be kept.
- Send JSON (
Content-Type: application/json). Pass input images as URLs, or local files as data URLs (data:image/png;base64,...), so nested fields likecontrolskeep working. Usemultipart/form-dataonly for simple uploads with flat fields.
Basics
- Base URL:
https://external.api.recraft.ai/v1 - Auth header:
Authorization: Bearer $RECRAFT_API_TOKEN - Token: created at https://app.recraft.ai/profile/api (needs a positive API units balance). 1 USD = 1,000 API units.
- Rate limits: 100 images per minute and 5 requests per second per user.
Minimal request
data: one item per image.urlis present withresponse_format: url(default);b64_jsonwithresponse_format: b64_json.credits: API units charged.style_id: present when a style was created from attached references.response_format: multipartreturnsmultipart/form-data: aresponsepart with the JSON above, then one part per image, named by itsimage_id(also in theContent-IDheader). Lowest latency.image_format:webp(default, lossless) orpngfor raster output. Vector output is always SVG.
Models
model value, output, price per image, and what each accepts on POST /v1/images/generations.
Which to pick:
- Default, best quality:
recraftv4_1. Print-ready 2K:_pro. SVG:_vector. - Product shots, mockups, flat predictable images:
recraftv4_1_utility*. - Fastest and cheapest (about 1.3 s), raster only, no styles:
recraftv4_1_flash. - Must match a given visual style from reference images:
recraftv4_styles*(a style is required). - Curated named styles,
negative_prompt, exact text placement, inpainting, outpainting, background operations:recraftv3/recraftv3_vector. - Cheapest vector, icons:
recraftv2_vector.
Generate image
POST /v1/images/generations. Variants that enforce the output type: POST /v1/images/generations/raster and POST /v1/images/generations/vector.
Exact sizes by model (same order as the
w:h list above):
Styles
POST /v1/styles creates a reusable style (0.005 USD). Returns {"id": "<style_id>", ...}.
Two ways to apply a style: create it once and pass
style_id (cheaper for repeated use), or attach style_reference_urls to each generation.
Edit an image
All take the input asimage_url (JSON: URL or data URL) or image (multipart file). Masks: mask_url / mask, grayscale, same size as the image, white = area to change, black = keep. Input limits: under 10 MB, up to 16 MP, max side 4096 px, min side 256 px. Mask pixels must be pure black (0) or pure white (255).
All accept
response_format and image_format. To avoid unwanted content (“no people, no text”) with V2 / V3 models, use negative_prompt, not controls.
Process an image
Input asimage_url (JSON) or file (multipart). No model field. Min side 256 px (32 px for crisp upscale).
These endpoints, and erase region, return a single image instead of a data array:
response.json()['image']['url'], not ['data'][0].
Other endpoints
POST /v1/prompts/enhancewith{"prompt": "..."}(up to 2,000 characters) returns{"enhanced_prompt": "..."}. 0.01 USD.GET /v1/users/mereturns{"id", "email", "name", "credits"}: the remaining API units balance.
Examples
Vector logo in brand colors:response_format: multipart):