翻篇收录说明
翻篇网页快照

Recraft API for AI Agents and LLMs - Recraft

https://www.recraft.ai/docs/api-reference/agents

最近抓取:2026-12-04 13:49:32(北京时间)

最近内容变化:2026-12-01 21:26:29(北京时间)

这是最近一次有效抓取的文本快照,不含网页脚本、图片和动态交互内容。实际网页可能已更新。

访问原网页

页面简介

The whole Recraft API on one page for AI agents and LLMs: rules, auth, every model id with price and parameters, every endpoint, limits, and working examples.

正文摘录

This page is written to be pasted into an AI agent (Claude, Cursor, ChatGPT, Copilot) as context. The Markdown version is at 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, Python requests, or JavaScript fetch. Do not use the OpenAI SDK unless asked; if you do, every non-OpenAI parameter must go in extra_body. Read the token from the RECRAFT_API_TOKEN environment variable. Never hard-code it. Always pass model explicitly. Pick it from the model table below. Only send parameters the chosen model supports (see the model table). Check against the table instead of relying on the API to catch a wrong parameter. On a non-2xx response, print the status code and the response body as text, then stop. Error bodies are plain text or JSON (a missing or invalid token returns 401 with text/plain request unauthorized), so never parse an error body as JSON without checking Content-Type. See Errors. 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 like controls keep working. Use multipart/form-data only 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://www.recraft.ai/app/api/api-keys (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 curl https://external.api.recraft.ai/v1/images/generations \ -H "Authorization: Bearer $RECRAFT_API_TOKEN" \ -H "Content-Type: application/json" \ -d '{"prompt": "two race cars on a track", "model": "recraftv4_1"}' import os import requests response = requests.post( 'https://external.api.recraft.ai/v1/images/generations', headers={'Authorization': f"Bearer {os.environ['RECRAFT_API_TOKEN']}"}, json={'prompt': 'two race cars on a track', 'model': 'recraftv4_1'}, ) if not response.ok: raise SystemExit(f'{response.status_code}: {response.text}') image_url = response.json()['data'][0]['url'] with open('image.webp', 'wb') as f: f.write(requests.get(image_url).content) Response of generation, image to image, remix, and the V3 edit endpoints: { "created": 1759140000, "credits": 35, "data": [{"image_id": "0e6a1b8c-5b1f-4a8e-9f3a-2c7d4e8b9a10", "url": "https://..."}] } data: one item per image. url is present with response_format: url (default); b64_json with response_format: b64_json. credits: API units charged. style_id: present when a style was created from attached references. response_format: multipart returns multipart/form-data: a response part with the JSON above, then one part per image, named by its image_id (also in the Content-ID header). Lowest latency. image_format: webp (default, lossless) or png for raster output. Vector output is always SVG. Models model value, output, price per image, and what each accepts on POST /v1/images/generations. modelOutputPricePrompt limitrecraftv4_1_flash_v2 (alias recraftv4_1_flash_v2_raster)Raster 1K0.007 USD10,000recraftv4_1 (default)Raster 1K0.035 USD10,000recraftv4_1_vectorSVG0.08 USD10,000recraftv4_1_proRaster 2K0.21 USD10,000recraftv4_1_pro_vectorSVG0.30 USD10,000recraftv4_1_utilityRaster 1K0.035 USD10,000recraftv4_1_utility_vectorSVG0.08 USD10,000recraftv4_1_utility_proRaster 2K0.21 USD10,000recraftv4_1_utility_pro_vectorSVG0.30 USD10,000recraftv4_stylesRaster 1K0.035 USD10,000recraftv4_styles_vectorSVG0.05 USD10,000recraftv4_styles_proRaster 2K0.10 USD10,000recraftv4_styles_pro_vectorSVG0.12 USD10,000recraftv4Raster 1K0.04 USD10,000recraftv4_vectorSVG0.08 USD10,000recraftv4_proRaster 2K0.25 USD10,000recraftv4_pro_vectorSVG0.30 USD10,000recraftv3Raster 1K0.04 USD1,000recraftv3_vectorSVG0.08 USD1,000recraftv2Raster 1K0.022 USD1,000recraftv2_vectorSVG0.044 USD1,000 Every raster model also accepts a _raster alias that behaves the same: recraftv2_raster, recraftv3_raster, recraftv4_raster, recraftv4_pro_raster, recraftv4_1_raster, recraftv4_1_pro_raster, recraftv4_1_utility_raster, recraftv4_1_utility_pro_raster, recraftv4_1_flash_v2_raster, recraftv4_styles_raster, recraftv4_styles_pro_raster. Prefer the base names. 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.1 s), raster only, no styles: recraftv4_1_flash_v2. 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. Parameter support by model family: ParameterV4.1 Flash V2V4.1, V4V4 StylesV3V2prompt, n, size, random_seed, response_format, image_format, zdryesyesyesyesyescontrols.colors, controls.background_coloryesyesyesyesyesstyle_id, style_reference_urls, style_referencesnoyesyes, one is requiredyesyesstyle_matchnoflexible, preciseflexible, preciseregularregularstyle (curated name, e.g. Photorealism, Illustration, Vector art; Icon (V2 vector only))nononoyesyesnegative_promptnononoyesyestext_layoutnononoyesnocontrols.artistic_level (0–5), controls.no_textnononoyesno Generate image POST /v1/images/generations. Variants that enforce the output type: POST /v1/images/generations/raster and POST /v1/images/generations/vector. FieldType, defaultNotespromptstring, requiredLimit per model above.modelstring, recraftv4_1Defaults to recraftv4_styles when style references are attached.ninteger, 11 to 6.sizestring, autoPrefer w:h: 1:1, 2:1, 1:2, 3:2, 2:3, 4:3, 3:4, 5:4, 4:5, 6:10, 14:10, 10:14, 16:9, 9:16. An exact WxH must be one of the model’s sizes (table below); anything else is rejected.style_idUUIDA style created for the same model. Cannot be combined with style references.style_reference_urlsarray of strings1 to 10 image URLs or data URLs (PNG, JPG, WEBP; 64 MB total). Creates a style for this request and returns its style_id. Costs 0.005 USD extra.style_referencesfilesMultipart counterpart of style_reference_urls.style_matchstringSee table above. Defaults to the style’s stored value.stylestringV2 / V3 curated style name.negative_promptstringV2 / V3.text_layoutarrayV3. [{"text": "WORD", "bbox": [[x, y], [x, y], [x, y], [x, y]]}], one word per item, coordinates 0 to 1 from the top-left. text allows uppercase Latin letters, digits, and basic punctuation only; see Text layout.controlsobject{"colors": [{"rgb": [255, 102, 0]}], "background_color": {"rgb": [255, 255, 255]}}. Up to 10 colors; optional weight per color (0 to 1, set for all or none, sum at most 1).random_seedintegerReproducibility.response_formatstring, urlurl, b64_json, multipart.image_formatstring, webpwebp or png.zdrbooleantrue turns on zero data retention: request inputs, such as the prompt or images, are not stored or logged. A result requested as url is still uploaded so it can be served. Cannot be combined with style references; style_id works. Exact sizes by model (same order as the w:h list above): ModelsSizesV4.1, V4.1 Utility, V4.1 Flash V2, V4, V4 Styles (1K)1024x1024, 1536x768, 768x1536, 1280x832, 832x1280, 1216x896, 896x1216, 1152x896, 896x1152, 832x1344, 1280x896, 896x1280, 1344x768, 768x1344V4.1 Pro, V4.1 Utility Pro, V4 Pro, V4 Styles Pro (2K)2048x2048, 3072x1536, 1536x3072, 2560x1664, 1664x2560, 2432x1792, 1792x2432, 2304x1792, 1792x2304, 1664x2688, 2560x1792, 1792x2560, 2688x1536, 1536x2688V3, V21024x1024, 2048x1024, 1024x2048, 1536x1024, 1024x1536, 1365x1024, 1024x1365, 1280x1024, 1024x1280, 1024x1707, 1434x1024, 1024x1434, 1820x1024, 1024x1820All vector modelsw:h ratios only Styles POST /v1/styles creates a reusable style (0.005 USD). Returns {"id": "<style_id>", ...}. FieldType, defaultNotesimage_urlsarray of stringsJSON. 1 to 10 reference image URLs or data URLs.filesfilesMultipart counterpart, any field name.modelstring, recraftv4_stylesThe model the style is for. The style only works with that model. Not recraftv4_1_flash_v2.matchstringflexible (default) or precise for V4 / V4.1; regular for V2 / V3.image_weightsarray of numbersOne per image. 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 as image_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 20 MB, up to 16 MP, max side 4096 px, min side 256 px. Mask pixels must be pure black (0) or pure white (255). EndpointWhat it doesRequired fieldsUseful optional fieldsModelsPricePOST /v1/images/imageToImageNew image from an image and a promptimage_url, prompt, strength (0 to 1, 1 = least similar)model, n, controls; V3 only: style, negative_promptV3, V4, V4.1 (not Flash V2); default recraftv4_10.04 USD / 0.08 USD with V3; see PricingPOST /v1/images/inpaintRegenerate the masked areaimage_url, mask_url, promptnegative_prompt, style, style_id, n, controlsrecraftv3, recraftv3_vector0.04 USD / 0.08 USDPOST /v1/images/outpaintExtend beyond the bordersimage_url, prompt, and at least one of: size, expand_left / expand_right / expand_top / expand_bottom (pixels), zoom_out_percentage. size and expand_* can’t be combined; zoom_out_percentage alone worksnegative_prompt, style, nrecraftv3, recraftv3_vector0.04 USD / 0.08 USDPOST /v1/images/replaceBackgroundNew background from a promptimage_url, promptnegative_prompt, style, nrecraftv3, recraftv3_vector0.04 USD / 0.08 USDPOST /v1/images/generateBackgroundGenerate the masked backgroundimage_url, mask_url, promptnegative_prompt, style, nrecraftv3, recraftv3_vector0.04 USD / 0.08 USDPOST /v1/images/eraseRegionRemove the masked obj