Connect API: Image editing is now available, powered by Canva Craft

The Connect API image generation endpoint can now edit an image, not only generate one from text. Give it an image and describe the change, and you get a new image back through the same job flow you already use. Add reference images and the prompt can refer to them: a logo to place on a product, a style to match, a person to keep consistent.

Editing is powered by Canva Craft (CRAFT-1 2K), the image model from Canva Research, the same model behind image editing in Dream Lab.

What’s new

  • A new optional images field on POST /v1/image-generations. It takes 1 to 12 images. The first image is the one to edit. Any further images are references the prompt can refer to by position (“the logo in the second image”).
  • Each image is either a publicly accessible HTTPS URL to a JPEG or PNG (up to 50 MB), or an image asset from the user’s Canva account by asset_id.
  • Set model to craft_v1_2k. It is the only model that accepts input images today. A request with images and another model, or no model, returns a 400.
  • Leave out aspect_ratio and the edited image keeps the shape of the first image. Set it to force a different shape.

How to use it

Same endpoint, same polling. Put the image to edit first and describe the change:

POST /v1/image-generations
{
  "prompt": "Put the logo from the second image on the side of the coffee cup. Keep the lighting and the background as they are.",
  "model": "craft_v1_2k",
  "images": [
    { "type": "url", "url": "https://example.com/images/coffee-cup.png" },
    { "type": "url", "url": "https://example.com/images/logo.png" }
  ],
  "idempotency_key": "6c0d1a2e-9f3b-4b7a-8c2d-5e1f0a9b3c47"
}

Then poll GET /v1/image-generations/{jobId} until status is success. The download URL is valid for 24 hours, or set asset_upload.type to upload to save the result to the user’s uploads.

To edit an image that is already in the user’s Canva account, use an asset input instead of a URL:

"images": [ { "type": "asset", "asset_id": "MAHcD13yglw" } ]

Asset inputs need a user access token with the asset:read scope as well as asset:write. URL inputs work with any token the endpoint accepts, including service apps.

This poster was made with Craft on the Connect API: generated from a prompt, then the label was changed with one images edit.

Usage notes

  • Edits take longer than text-to-image. Expect roughly 30 to 60 seconds for one or two input images, longer with more references. Poll with backoff.
  • For public and private apps, starting a job uses the user’s AI credits, as with generation. For service apps, an edit is 3 credits per 2K image including the first input image, plus 0.6 credits for each additional input image. See the credit rates.
  • A URL must be fetchable without extra request headers. If an input image can’t be downloaded, the job fails with internal_error and the message “An input image could not be downloaded”, and the credits are returned.
  • Asset inputs return 404 asset_not_found for an asset the user can’t read, 400 unsupported_content_type for a non-image asset, and 400 asset_not_ready while an upload is still importing.
  • Prompts, input images and outputs go through the same safety checks as generation. Rejected content returns unsafe_input.

Docs & details

Reminder

The image generation APIs are in preview, so breaking changes may happen. Model additions, including more models that accept images, are announced in the Changelog.

Feedback & questions

Reply on this thread with feedback or questions. We’d love to see what you edit with it.