Create image generation job
This API is currently provided as a preview. Be aware of the following:
- There might be unannounced breaking changes.
- Any breaking changes to preview APIs won't produce a new API version.
- Public apps that use preview APIs will not pass the review process, and can't be made available to all Canva users.
Starts a new asynchronous job to generate an image from a plain-text prompt. When the image is generated, you can download it using the URL provided. The download URL is only valid for 24 hours.
The request requires a prompt and an idempotency key. Call this API with a user access token that has the asset:write scope.
To also save the generated image to the user's Canva account as an image asset, set asset_upload to type: upload. The job then returns the asset alongside the download URL. Saving the asset requires a user access token.
Starting a job consumes the user's AI credit allowance(opens in a new tab or window). If the user has reached their AI allowance limit, the request returns a 402 error with the credit_quota_exceeded code.
For more information on the workflow for using asynchronous jobs, see API requests and responses. You can check the status and get the results of image generation jobs created with this API using the Get image generation job API.
HTTP method and URL path
https://api.canva.com /rest /v1 /image-generationsRate limit
This operation's rate limit depends on your app type:
App type | Rate limit |
|---|---|
Public or private apps (acts on behalf of a user using the OAuth authorization code flow) | 20 requests per minute for each user of your app |
Service apps (acts on behalf of your app itself using the OAuth client credentials flow) | 1000 requests per minute for your app |
Authentication and authorization
This endpoint requires a valid OAuth access token. For more information, see Generate an access token.
Scopes
The access token must have the following scopes (permissions), depending on your app type:
App type | Required scopes |
|---|---|
Public or private apps (acts on behalf of a user using the OAuth authorization code flow) |
|
Service apps (acts on behalf of your app itself using the OAuth client credentials flow) |
|
Capabilities
Capabilities only apply to public or private apps, which act on behalf of a user. The user must have at least one of the following capabilities:
image_generation
Header parameters
Content-TypestringIndicates the media type of the information sent in the request. This must be set to application/json.
For example: Content-Type: application/json
Body parameters
promptstringA plain-text description of the image to generate.
Minimum length: 1
Maximum length: 10000
idempotency_keystringA key to make create requests idempotent. Retrying with the same key returns the original job without creating a duplicate, even if the other request parameters differ. Keys are held for 24 hours from job creation.
aspect_ratiostringThe aspect ratio of the generated image. Every aspect ratio is supported by every model
you can select with model, so the choice of model never limits the aspect ratios you
can use. The pixel dimensions of the output depend on the model. The job result reports
the actual width and height. If you omit the aspect ratio, Canva chooses one for the
image. Don't rely on a specific default: set the aspect ratio when the shape matters.
Available values:
square: A square (1:1) image.landscape: A wide (16:9) image, suitable for landscape-oriented content.portrait: A tall (9:16) image, suitable for portrait-oriented content.landscape_3_2: A wide (3:2) image, suitable for photos and print.portrait_2_3: A tall (2:3) image, suitable for posters and portrait photos.portrait_4_5: A tall (4:5) image, suitable for social media feed posts.landscape_4_3: A wide (4:3) image, suitable for presentations and classic photos.portrait_3_4: A tall (3:4) image, suitable for portrait prints and social media.landscape_5_4: A wide (5:4) image, suitable for prints and framed photos.landscape_2_1: A wide (2:1) image, suitable for banners and panoramic headers.portrait_1_2: A tall (1:2) image, suitable for tall banners and pins.
modelstringThe model to use for image generation. We recommend omitting this parameter: Canva then selects the best available model for the request and falls back to another model if one is temporarily unavailable. Set it only if you need a specific model's output. If the requested model can't serve the request, the job fails. Canva never uses a different model to serve the request.
The model strengths below are based on Canva's evaluations. Results vary by prompt, so test with your own prompts before pinning a model.
Available values:
craft_v1_2k: CRAFT-1 2K, Canva's first-party image generation model. Pick this model for the best image quality for infographics, posters, slides, people and portraits, abstract art, patterns, landscapes, nature, products, and marketing materials.lucid_origin: Lucid Origin. Pick this for architecture, logos, posters, or sci-fi and fantasy scenes.z_image_turbo: Z Image Turbo. Pick this if the image includes text, or for food, drink, and general-purpose imagery.
asset_uploadImageGenerationAssetUploadWhether to save the generated image as an image asset in the user's Canva account.
Omitting asset_upload (or using type: none) returns only a download URL.
Saving the asset (type: upload) requires a user access token.
Don't save the generated image. The result contains only its download URL.
typestringAvailable values: The only valid value is none.
Save the generated image as an image asset in the user's Canva account. The asset appears
in the user's Uploads, and the generated image in the result includes the asset
alongside its download url.
typestringAvailable values: The only valid value is upload.
asset_namestringA name for the image asset. Canva doesn't localize this value, so provide a name in the user's language. If omitted, Canva generates a name for the asset.
Minimum length: 1
Maximum length: 255
Example request
Examples for using the /v1/image-generations endpoint:
curl --request POST 'https://api.canva.com/rest/v1/image-generations' \--header 'Authorization: Bearer {token}' \--header 'Content-Type: application/json' \--data '{"prompt": "string","aspect_ratio": "square","model": "craft_v1_2k","idempotency_key": "550e8400-e29b-41d4-a716-446655440000","asset_upload": {"type": "none"}}'
const fetch = require("node-fetch");fetch("https://api.canva.com/rest/v1/image-generations", {method: "POST",headers: {"Authorization": "Bearer {token}","Content-Type": "application/json",},body: JSON.stringify({"prompt": "string","aspect_ratio": "square","model": "craft_v1_2k","idempotency_key": "550e8400-e29b-41d4-a716-446655440000","asset_upload": {"type": "none"}}),}).then(async (response) => {const data = await response.json();console.log(data);}).catch(err => console.error(err));
import java.io.IOException;import java.net.URI;import java.net.http.*;public class ApiExample {public static void main(String[] args) throws IOException, InterruptedException {HttpRequest request = HttpRequest.newBuilder().uri(URI.create("https://api.canva.com/rest/v1/image-generations")).header("Authorization", "Bearer {token}").header("Content-Type", "application/json").method("POST", HttpRequest.BodyPublishers.ofString("{\"prompt\": \"string\", \"aspect_ratio\": \"square\", \"model\": \"craft_v1_2k\", \"idempotency_key\": \"550e8400-e29b-41d4-a716-446655440000\", \"asset_upload\": {\"type\": \"none\"}}")).build();HttpResponse<String> response = HttpClient.newHttpClient().send(request,HttpResponse.BodyHandlers.ofString());System.out.println(response.body());}}
import requestsheaders = {"Authorization": "Bearer {token}","Content-Type": "application/json"}data = {"prompt": "string","aspect_ratio": "square","model": "craft_v1_2k","idempotency_key": "550e8400-e29b-41d4-a716-446655440000","asset_upload": {"type": "none"}}response = requests.post("https://api.canva.com/rest/v1/image-generations",headers=headers,json=data)print(response.json())
using System.Net.Http;var client = new HttpClient();var request = new HttpRequestMessage{Method = HttpMethod.Post,RequestUri = new Uri("https://api.canva.com/rest/v1/image-generations"),Headers ={{ "Authorization", "Bearer {token}" },},Content = new StringContent("{\"prompt\": \"string\", \"aspect_ratio\": \"square\", \"model\": \"craft_v1_2k\", \"idempotency_key\": \"550e8400-e29b-41d4-a716-446655440000\", \"asset_upload\": {\"type\": \"none\"}}",Encoding.UTF8,"application/json"),};using (var response = await client.SendAsync(request)){response.EnsureSuccessStatusCode();var body = await response.Content.ReadAsStringAsync();Console.WriteLine(body);};
package mainimport ("fmt""io""net/http""strings")func main() {payload := strings.NewReader(`{"prompt": "string","aspect_ratio": "square","model": "craft_v1_2k","idempotency_key": "550e8400-e29b-41d4-a716-446655440000","asset_upload": {"type": "none"}}`)url := "https://api.canva.com/rest/v1/image-generations"req, _ := http.NewRequest("POST", url, payload)req.Header.Add("Authorization", "Bearer {token}")req.Header.Add("Content-Type", "application/json")res, _ := http.DefaultClient.Do(req)defer res.Body.Close()body, _ := io.ReadAll(res.Body)fmt.Println(string(body))}
$curl = curl_init();curl_setopt_array($curl, array(CURLOPT_URL => "https://api.canva.com/rest/v1/image-generations",CURLOPT_CUSTOMREQUEST => "POST",CURLOPT_RETURNTRANSFER => true,CURLOPT_HTTPHEADER => array('Authorization: Bearer {token}','Content-Type: application/json',),CURLOPT_POSTFIELDS => json_encode(["prompt" => "string","aspect_ratio" => "square","model" => "craft_v1_2k","idempotency_key" => "550e8400-e29b-41d4-a716-446655440000","asset_upload" => ["type" => "none"]])));$response = curl_exec($curl);$err = curl_error($curl);curl_close($curl);if (empty($err)) {echo $response;} else {echo "Error: " . $err;}
require 'net/http'require 'uri'url = URI('https://api.canva.com/rest/v1/image-generations')http = Net::HTTP.new(url.host, url.port)http.use_ssl = truerequest = Net::HTTP::Post.new(url)request['Authorization'] = 'Bearer {token}'request['Content-Type'] = 'application/json'request.body = <<REQUEST_BODY{"prompt": "string","aspect_ratio": "square","model": "craft_v1_2k","idempotency_key": "550e8400-e29b-41d4-a716-446655440000","asset_upload": {"type": "none"}}REQUEST_BODYresponse = http.request(request)puts response.read_body
Success response
If successful, the endpoint returns a 200 response with a JSON body with the following parameters:
jobImageGenerationJobDetails about the image generation job. If the job status is success, the job's
result is present.
idstringThe image generation job ID.
statusstringThe status of the image generation job. A newly created job will be in_progress and
will eventually become success or failed. If the status is success, the job's
result is present.
Available values:
failedin_progresssuccess
resultImageGenerationJobResultResult of the image generation job. Only present if job status is success.
imageGeneratedImageA generated image.
urlstringA download URL for the generated image. The download URL is only valid for 24 hours.
widthintegerThe width of the generated image in pixels.
heightintegerThe height of the generated image in pixels.
assetobjectThe image asset the generated image was saved as. Only present if the job was created
with asset_upload set to type: upload and the asset still exists (for example, it's
absent if the user has since deleted the asset).
typestringType of an asset.
Available values:
imagevideo
idstringThe ID of the asset.
namestringThe name of the asset.
created_atintegerWhen the asset was added to Canva, as a Unix timestamp (in seconds since the Unix Epoch).
updated_atintegerWhen the asset was last updated in Canva, as a Unix timestamp (in seconds since the Unix Epoch).
thumbnailThumbnailA thumbnail image representing the object.
widthintegerThe width of the thumbnail image in pixels.
heightintegerThe height of the thumbnail image in pixels.
urlstringA URL for retrieving the thumbnail image. This URL expires after 15 minutes. This URL includes a query string that's required for retrieving the thumbnail.
errorImageGenerationErrorIf the image generation job fails, this object provides details about the error. Only present if status is failed.
codestringError code indicating what went wrong with the image generation.
Available values:
unsafe_input: Content safety checks rejected the prompt.timeout: The generation did not complete in time.model_not_available: The requested model can't currently serve this request, and Canva doesn't retry the job with another model. This is usually temporary. Retry later, retry without themodelparameter to use automatic model selection, or retry with a different model.model_retired: The requested model has been permanently retired from this version of the API, and you can't use it again in this version. Use a different model. The API documentation lists retired models, which keep their enum value for the lifetime of this API version.internal_error: An unexpected error occurred during generation.
messagestringA human-readable description of what went wrong.
Example response
{"job": {"id": "string","status": "failed","result": {"image": {"url": "string","asset": {"type": "image","id": "Msd59349ff","name": "My Awesome Upload","tags": ["image","holiday","best day ever"],"created_at": 1377396000,"updated_at": 1692928800,"thumbnail": {"width": 595,"height": 335,"url": "https://document-export.canva.com/Vczz9/zF9vzVtdADc/2/thumbnail/0001.png?<query-string>"}},"width": 1024,"height": 1024}},"error": {"code": "unsafe_input","message": "string"}}}
Error responses
400 Bad Request
codestringA short string indicating what failed. This field can be used to handle errors programmatically. For a complete list of error codes, see Error responses.
messagestringA human-readable description of what went wrong.
Example error responses
The request field does not match expected format
{"code": "invalid_request","message": "{fieldValue} does not match expected format for {fieldName}"}
A required header is missing
{"code": "invalid_request","message": "missing required header {headerName}"}
Access token is missing from the request
{"code": "invalid_request","message": "Access token is missing from the request."}
Client credentials are missing from the request
{"code": "invalid_request","message": "Client credentials are missing from the request."}
Content-Type header is missing
{"code": "invalid_header_value","message": "Content-Type header is missing for {path}"}
Content-Type header is invalid
{"code": "invalid_header_value","message": "Content-Type {contentType} is invalid for {path}"}
Validating client failed
{"code": "unauthorized_client","message": "Validating client failed for {clientAppId}"}
Validating client failed with error code
{"code": "unauthorized_client","message": "Validating client failed for {clientAppId}: {errorCode}"}
Client secret is invalid
{"code": "invalid_client","message": "Client secret is invalid for {clientAppId}"}
Number of column-separated components in the base64 value is not 2
{"code": "invalid_request","message": "Malformed encoded client ID and secret"}
Could not decode the base64 value for client credentials
{"code": "invalid_request","message": "Credentials could not be decoded from base64"}
Failed to read request body
{"code": "bad_request_body","message": "Failed to read request body"}
Expected integer for query parameter
{"code": "bad_query_params","message": "Expected integer for query parameter `{key}` but found {value}"}
Expected long for query parameter
{"code": "bad_query_params","message": "Expected long for query parameter `{key}` but found {value}"}
Expected long list for query parameter
{"code": "bad_query_params","message": "Expected long list for query parameter `{key}` but found {value}"}
Expected 1 query parameter but found multiple
{"code": "bad_query_params","message": "Expected 1 query parameter {key} but found {count}"}
Missing required query parameter
{"code": "bad_query_params","message": "Missing required query parameter: {key}"}
Confidential clients must not authenticate via CORS requests
{"code": "unauthorized_client","message": "Confidential clients must not authenticate via CORS requests"}
The request URI could not be parsed
{"code": "bad_request_params","message": "Invalid URI: {uri}"}
The Origin header could not be parsed
{"code": "bad_request_params","message": "Invalid Origin: {origin}"}
One or more IDs could not be deobfuscated
{"code": "invalid_field","message": "Invalid Ids: {ids}"}
401 Unauthorized
codestringA short string indicating what failed. This field can be used to handle errors programmatically. For a complete list of error codes, see Error responses.
messagestringA human-readable description of what went wrong.
Example error responses
The OAuth client credentials are invalid
{"code": "invalid_client","message": "Client {clientId} not available"}
Access token could not be decoded or signature could not be verified.
{"code": "invalid_access_token","message": "Access token is invalid"}
Client credentials or body auth are missing from the request
{"code": "invalid_client","message": "Client credentials or body auth are missing from the request."}
Authorization header has wrong number of components
{"code": "invalid_access_token","message": "Malformed Authorization header: wrong number of components"}
Authorization header has invalid mode
{"code": "invalid_access_token","message": "Malformed Authorization header: invalid mode"}
Token couldn't be introspected
{"code": "invalid_access_token","message": "Token couldn't be introspected"}
Access token is revoked
{"code": "revoked_access_token","message": "Access token is revoked"}
Missing Authorization header
{"code": "invalid_access_token","message": "Missing Authorization header"}
Malformed Authorization header
{"code": "invalid_access_token","message": "Malformed Authorization header"}
402 Payment Required
codestringA short string indicating what failed. This field can be used to handle errors programmatically. For a complete list of error codes, see Error responses.
messagestringA human-readable description of what went wrong.
Example error responses
User has reached their credit quota limit
{"code": "credit_quota_exceeded","message": "User has exceeded their credit quota"}
App has reached its credit quota limit
{"code": "app_credit_quota_exceeded","message": "App has exceeded its credit quota"}
403 Forbidden
codestringA short string indicating what failed. This field can be used to handle errors programmatically. For a complete list of error codes, see Error responses.
messagestringA human-readable description of what went wrong.
Example error responses
Image generation is not enabled for this client
{"code": "permission_denied","message": "Image generation is not enabled"}
The required OAuth scope is missing
{"code": "missing_scope","message": "Missing scopes: {scopes}"}
Request must be made on behalf of a user
{"code": "user_role_required","message": "This request must be made on behalf of a user."}
429 Too Many Requests
codestringA short string indicating what failed. This field can be used to handle errors programmatically. For a complete list of error codes, see Error responses.
messagestringA human-readable description of what went wrong.
Example error responses
The requested image generation model has reached capacity
{"code": "model_capacity_reached","message": "The requested model has reached capacity. Try again later or choose a different model."}
Rate limit exceeded
{"code": "too_many_requests","message": "Too many requests to {operation}"}