页面简介
Get a Recraft API key (token) and generate your first image with one request in cURL, Python, or JavaScript.
正文摘录
Generate your first image with the Recraft API in about two minutes. 1Get an API keyRecraft calls API keys tokens. Open API tokens and select Create token. The selected account needs a positive API unit balance; add units if needed. All tokens for that account share its balance.2Save it as an environment variableexport RECRAFT_API_TOKEN=your_token Every example in these docs reads the token from RECRAFT_API_TOKEN.3Make a requestcURLPythonPython (OpenAI SDK)JavaScriptcurl 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"}' Without a model, the request uses Recraft V4.1 at $0.035 per image.4Get the imageThe response lists the generated images:{ "created": 1759140000, "credits": 35, "data": [ { "image_id": "0e6a1b8c-5b1f-4a8e-9f3a-2c7d4e8b9a10", "url": "https://..." } ] } Download the file from data[0].url: image URLs are temporary and files are kept for about 24 hours. credits is the number of API units the request cost. Authentication All requests authenticate with a Bearer token in the Authorization header: Authorization: Bearer RECRAFT_API_TOKEN The base URL is https://external.api.recraft.ai/v1. The API follows REST principles, so any HTTP client works. To use the OpenAI Python library instead, see Clients and SDKs. Next steps Choose a modelCompare every model by price, output, and best use case.Fast generationAbout 1.1 seconds and $0.007 per image with V4.1 Flash V2.Vector outputGet editable SVG with a _vector model.Generate in a styleMatch a style from your own reference images.Edit imagesImage to image, inpainting, vectorizing, upscaling, and more.Use with AI toolsGive Claude, ChatGPT, or Cursor the docs to write your integration. All operations The API also covers: Create style, reusable custom styles from reference images. Image to image, inpainting, and outpainting. Replace background, generate background, and remove background. Vectorize image, crisp upscale, and creative upscale. Enhance details, erase region, and remix image. Enhance prompt and get user information. An interactive Swagger reference is also available.