API Platform

Concepts

Files & Drive

Models take input assets as URLs and return results as URLs hosted on the Picsart CDN. Turn on Drive to save generated media to an organized folder automatically. Text results do not use this media storage flow.

Page as Markdown

Input files#

Any model that takes an image, video, or audio input reads it from a publicly reachable URL — for example imageUrls, videoUrl, startFrame, or audioUrl. Each model page lists the exact keys it accepts.

// Input assets are passed as public URLs — imageUrls, videoUrl,
// startFrame, endFrame, audioUrl, … depending on the model.
const result = await ai.generate('seedream-5.0-pro', {
  prompt: 'Replace the background with a snowy forest',
  imageUrls: ['https://cdn.example.com/photo.jpg'],
});

console.log(result.url);

Getting a URL for a local file

The SDK and REST API expect a URL you host (your own CDN/bucket, a signed URL, or a Picsart Drive asset). The gen-ai CLI is the shortcut: pass a local path with -i and it uploads the file and forwards the URL for you.

Output files & the CDN#

In the SDK, result.url is the primary media asset and result.items holds multiple outputs when available. Direct REST calls return the model-specific output inside response.result. Check the model's response schema before you read a URL from it.

  • SDK / REST: download the URL, or save it to Drive for an organized copy (below). Keep a copy in your own storage when you need to retain a result independently of its hosted URL.
  • CLI: results download to ./output by default — pass --no-download to print the URL only.

File requirements#

Check your model page for accepted formats, dimensions, duration, and file size. Requirements differ by model. A limit from a legacy image endpoint does not apply to every model on this platform.

Input URLs must remain accessible while the request runs. Check access permissions and signed URL expiry if a file cannot load. Do not make private media public to diagnose a request. Use a non-sensitive test file instead.

Auto-save to Drive#

Pass a drive config when creating the client and every generate() result is saved to that folder in Picsart Drive, along with the model id and the parameters that produced it. In TypeScript the saved file is returned on result.drive.

import { createClient } from '@picsart/ai-sdk';

const ai = createClient({
  apiKey: process.env.PICSART_API_KEY,
  apiUrl: 'https://api.green-salad-4efd.toolsminati.workers.dev',
  // Enable Drive — every generation is saved to this folder.
  drive: { folder: 'AI Playground' },
});

const result = await ai.generate('flux-2-pro', {
  prompt: 'A serene mountain lake at golden hour',
});

console.log(result.url);          // CDN URL of the generated image
console.log(result.drive?.uid);   // uid of the file saved in Drive
console.log(result.drive?.folder); // { name, uid }

Override the filename or target board per call with the drive option:

// Override the filename and target board (subfolder) for a single call.
await ai.generate(
  'flux-2-pro',
  { prompt: 'hero banner, spring sale' },
  {
    drive: {
      name: 'spring-hero.png',
      folder: { path: 'AI Playground/Landing' },
    },
  },
);

Note

Text generations (generateText()) return strings rather than assets and are not saved to Drive.

Working with Drive#

When Drive is configured, ai.drive exposes the full folder and file surface — list assets, organize boards, save external URLs, and read back the generation metadata. The Python methods are the same names in snake_case.

// ai.drive is available whenever the client is created with a `drive` config.

// List recent images across all boards
const images = await ai.drive!.list({ type: 'image' });
for (const item of images) console.log(item.name, item.url);

// The same, with full generation metadata (model, prompt, params, …)
const detailed = await ai.drive!.listDetailed({ type: 'video' });

// Organize into boards (subfolders under the root folder)
const board = await ai.drive!.ensureFolder('Campaign Q3');

// Save an existing asset (by URL) straight into Drive
await ai.drive!.save(
  {
    url: 'https://cdn.example.com/asset.png',
    name: 'asset.png',
    resourceType: 'PHOTO',
  },
  board ?? undefined,
);

// Read back what produced a generation
const gen = await ai.drive!.getGeneration(images[0].uid);
console.log(gen?.model, gen?.aiSDKPayload?.prompt);

Next steps#