页面简介
Every Recraft API endpoint with its price and docs page, plus the full reference for image generation, styles, controls, and text layout.
正文摘录
Every Recraft API endpoint at a glance, plus the full reference for image generation, styles, and the shared controls and text_layout objects. Each tool has its own page with a runnable request. Authentication All requests need an Authorization: Bearer RECRAFT_API_TOKEN header. See the Quickstart to get a token. Python examples on this page come in two variants: plain HTTP with requests, and the OpenAI Python library (see Clients and SDKs for how it maps to the Recraft API). All endpoints Base URL: https://external.api.recraft.ai/v1. Every endpoint takes JSON (images as URLs or data URLs) or multipart/form-data (images as files). EndpointRequestPriceDocsGenerate imagePOST /images/generationsper modelbelow, modelsCreate stylePOST /styles$0.005belowList, get, or delete stylesGET /styles, GET /styles/{style_id}, DELETE /styles/{style_id}, GET /styles/basic—belowImage to imagePOST /images/imageToImageper modelImage to imageInpaintingPOST /images/inpaint$0.04 / $0.08InpaintingOutpaintingPOST /images/outpaint$0.04 / $0.08OutpaintingReplace backgroundPOST /images/replaceBackground$0.04 / $0.08BackgroundGenerate backgroundPOST /images/generateBackground$0.04 / $0.08BackgroundVectorizePOST /images/vectorize$0.01 / $0.04 with Vectorizer Pro (v1_pro)VectorizeRemove backgroundPOST /images/removeBackground$0.01Remove backgroundErase regionPOST /images/eraseRegion$0.002Erase regionCrisp upscalePOST /images/crispUpscale$0.004UpscaleCreative upscalePOST /images/creativeUpscale$0.25UpscaleEnhance detailsPOST /images/enhance$0.21Enhance detailsRemix imagePOST /images/variateImage$0.04RemixEnhance promptPOST /prompts/enhance$0.01Enhance promptUser informationGET /users/me—below Raster / vector prices are for recraftv3 / recraftv3_vector. See Pricing for every model. Image inputs and results The API accepts input images and returns generated images in several formats, so you can pick the one that fits your client best: Inputs — send an image or a mask as a multipart file (image, mask, file, …), or reference it in a JSON body by URL or data URL in the matching *_url field. Results — choose how generated images come back with response_format: a download url (default), Base64 in b64_json, or raw bytes in a multipart response. Image format — raster images come back as lossless WebP by default, pass image_format: png to get PNG instead. Both are described in detail in Image inputs and results. For the best latency use response_format: multipart. Generate image Creates an image given a prompt. POST https://external.api.recraft.ai/v1/images/generations In addition to the general endpoint above, two specialized variants accept the same request body but constrain the allowed model and style values to a single output type: POST https://external.api.recraft.ai/v1/images/generations/raster POST https://external.api.recraft.ai/v1/images/generations/vector /generations/raster — only raster models (any model from the list above whose name does not end in _vector) and raster styles are accepted. Requests using a vector model or vector style are rejected. /generations/vector — only vector models (any model from the list above whose name ends in _vector) and vector styles are accepted. Requests using a raster model or raster style are rejected. Use these variants when you want the server to enforce the output type — for example, in an agent or workflow that must produce only raster (or only vector) images. The base /generations endpoint remains available and accepts any supported model or style. Example PythonPython (OpenAI SDK)cURLimport 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': 'race car on a track', }, ) if not response.ok: raise SystemExit(f'{response.status_code}: {response.text}') print(response.json()['data'][0]['url']) Parameters ParameterTypeDescriptionCompatibilityprompt (required)stringA text description of the desired image(s).Maximum prompt length depends on model, refer to Appendixninteger or null, default is 1The number of images to generate, must be between 1 and 6.All modelsmodelstring or null, default is recraftv4_1The model to use for image generation. When style references are attached, defaults to recraftv4_styles.See All models for every model value.sizestring or nullThe size of the generated images in WxH or w:h format. If not specified, the size is auto-selected based on the prompt.Depends on model, supported values are published in Appendixstylestring or nullThe style of the generated images, refer to Styles.All models except V4.1 Flash V2style_idUUID or nullUse a style as visual reference, refer to Styles.All models except V4.1 Flash V2style_matchstring or nullControls how closely the generated images match the referenced style, refer to Styles. Must be one of regular, precise, flexible. When omitted, the style’s stored value (or the model default) is used. A value not supported by the resolved model is rejected.regular — V2 / V3 models;flexible, precise — V4 / V4.1 models (except V4.1 Flash V2)style_referencesfiles(multipart only) Style reference images. See Style references.All models except V4.1 Flash V2style_reference_urlsarray of strings or null(JSON only) URLs or data URLs of the style reference images, the JSON-body counterpart of style_references. See Style references.All models except V4.1 Flash V2negative_promptstring or nullA text description of undesired elements on an image.V2 / V3 modelsrandom_seedinteger or nullSeed for reproducible generation.All modelsresponse_formatstring or null, default is urlThe format in which the generated images are returned. Must be one of url, b64_json or multipart, see Image results.All modelsimage_formatstring or null, default is webpThe file format of the returned raster images. Must be one of webp or png, see Image format.All modelszdrboolean or nullSet to true to turn on zero data retention for the request. Can’t be combined with style references.All modelstext_layoutArray of objects or nullRefer to Text Layout.V3 models onlycontrolsobject or nullA set of custom parameters to tweak generation process, refer to Controls.All models, partially supported for V4 / V4.1 Note: when using the V4 Styles models, a style must be specified — either via style_id, or via style references. A request without one is rejected. Note: the V4.1 Flash V2 model (recraftv4_1_flash_v2) does not support styles: style, style_id, style_match, and style references are not supported with it. Style references Instead of referencing an existing style by style_id, you can attach style reference images directly to a generation request. When present, the server creates a private style from these images and applies it to the generation. The resolved style’s id is returned as style_id in the response, so you can reuse it in later requests. Provide the images as style_references (multipart file parts, any field name) or as style_reference_urls (URLs or data URLs, JSON only). Images must be in PNG, JPG, or WEBP format. The maximum number of images is 10, and their total size is limited to 64 MB (each file must also be under the 20 MB upload limit). V2, V3, V4 and V4.1 models (including the dedicated V4 Styles model, but not V4.1 Flash V2) support style references; when no model is specified the request defaults to recraftv4_styles. Combining style references with style_id is rejected. Billing is composite: creating the style is charged once, in addition to the per-image generation cost. The response credits field is the sum of both. Style references can’t be combined with zero data retention: they create a stored style, so a request with both is rejected. Pass a style_id instead. Example Python (Multipart)Python (JSON)Python (OpenAI SDK)cURL (Multipart)cURL (JSON)import os import requests response = requests.post( 'https://external.api.recraft.ai/v1/images/generations', headers={'Authorization': f"Bearer {os.environ['RECRAFT_API_TOKEN']}"}, data={ 'prompt': 'race car on a track', 'model': 'recraftv4_styles', }, files={'style_references': open('reference.png', 'rb')}, ) if not response.ok: raise SystemExit(f'{response.status_code}: {response.text}') print(response.json()['data'][0]['url']) print(response.json()['style_id']) Create style Upload a set of images to create a style reference. POST https://external.api.recraft.ai/v1/styles Example Python (Multipart)Python (JSON)Python (OpenAI SDK)cURL (Multipart)cURL (JSON)import os import requests response = requests.post( 'https://external.api.recraft.ai/v1/styles', headers={'Authorization': f"Bearer {os.environ['RECRAFT_API_TOKEN']}"}, data={ 'model': 'recraftv4_styles', }, files={'file1': open('image.png', 'rb')}, ) if not response.ok: raise SystemExit(f'{response.status_code}: {response.text}') print(response.json()['id']) Response { "id": "229b2a75-05e4-4580-85f9-b47ee521a00d", "style": "any", "creation_time": "2024-01-01T00:00:00Z", "is_private": true, "credits": 5 } Parameters Upload a set of images to create a style reference. ParameterTypeDescriptionCompatibilityfilesfiles(multipart only) Images in PNG, JPG, or WEBP format for use as style references, sent as multipart file parts (any field name). The max number of images is 10. Total size of all images is limited to 64 MB (each file must also be under the 20 MB upload limit).All modelsimage_urlsarray of strings(JSON only) URLs or data URLs of the reference images, the JSON-body counterpart of files. Same image format, count, and size limits apply.All modelsmodelstring or null, default is recraftv4_stylesThe transform model the style is created for.All models except V4.1 Flash V2matchstring or nullHow closely images generated with this style should match it, refer to Styles; the value is stored on the style and used at generation time. When omitted, defaults to regular for V2 / V3 models and to flexible for V4 / V4.1 models.regular — V2 / V3 models;flexible (defa