Skip to content

feat: add uploader.generate to generate and upload AI images#737

Open
mckomo-cl wants to merge 1 commit into
masterfrom
feature/uploader-generate
Open

feat: add uploader.generate to generate and upload AI images#737
mckomo-cl wants to merge 1 commit into
masterfrom
feature/uploader-generate

Conversation

@mckomo-cl

Copy link
Copy Markdown
Contributor

Brief Summary of Changes

Adds a new cloudinary.v2.uploader.generate() method that generates an image from a text prompt using Cloudinary's image generation API and uploads the generated image to your product environment — in a single call.

  • New method uploader.generate(generateParams, options, callback) — the same envelope as uploader.upload, but the first argument carries the generation parameters (prompt is required; model_family, quality_tier, model_id, width, height, seed are optional).
  • Internally it calls the image generation API and then uploads the resulting image (via the secure_url returned by the generation API) by delegating to uploader.upload. The resolved value / callback result is therefore the upload response, so all standard upload options (folder, tags, context, metadata, …) are honored.
  • On a generation failure the error is propagated using the standard SDK error handling (rejected promise + error callback); the upload step is not attempted.
  • New internal API client call_generate_api (JSON body + Basic Auth / OAuth) mirroring call_analysis_api, plus a base_processing_api_url helper for the v2 processing endpoint.
  • TypeScript types added (GenerateImageOptions interface and generate overloads).

Usage

const cloudinary = require('cloudinary').v2;

cloudinary.config({
  cloud_name: 'my_cloud',
  api_key: '************',
  api_secret: '************',
});

// Generate an image from a prompt and upload it with advanced upload options.
const result = await cloudinary.uploader.generate(
  {
    prompt: 'A photorealistic sunset over a mountain lake, 8K detail',
    model_family: 'flux',
    quality_tier: 'premium',
    width: 1024,
    height: 768,
  },
  {
    folder: 'ai/landscapes',
    tags: ['ai-generated', 'sunset'],
    context: { alt: 'AI generated sunset', caption: 'Mountain lake at dusk' },
  },
);

console.log(result);
// The resolved value is the *upload* response of the generated image, e.g.:
// {
//   asset_id: 'a1b2c3d4e5f60718293a4b5c6d7e8f90',
//   public_id: 'ai/landscapes/xyz789',
//   version: 1718600000,
//   signature: 'abcdef1234567890abcdef1234567890abcdef12',
//   width: 1024,
//   height: 768,
//   format: 'png',
//   resource_type: 'image',
//   created_at: '2026-06-17T10:30:00Z',
//   tags: ['ai-generated', 'sunset'],
//   bytes: 2048576,
//   type: 'upload',
//   etag: '7f1e2d3c4b5a69788',
//   url: 'http://res.cloudinary.com/my_cloud/image/upload/v1718600000/ai/landscapes/xyz789.png',
//   secure_url: 'https://res.cloudinary.com/my_cloud/image/upload/v1718600000/ai/landscapes/xyz789.png',
//   folder: 'ai/landscapes',
//   context: { custom: { alt: 'AI generated sunset', caption: 'Mountain lake at dusk' } },
//   original_filename: 'xyz789',
// }

Callback style is also supported, identical to upload:

cloudinary.uploader.generate(
  { prompt: 'A man with a hat' },
  { folder: 'ai/portraits', tags: ['ai-generated'] },
  (error, result) => {
    console.log(result, error);
  },
);

What Does This PR Address?

  • GitHub issue (Add reference - #XX)
  • Refactoring
  • New feature
  • Bug fix
  • Adds more tests

Are Tests Included?

  • Yes
  • No

Reviewer, Please Note:

  • The generation endpoint uses JSON + Basic Auth (like the Admin / Analysis APIs), not the multipart/signed transport used by upload. The new call_generate_api client handles this and reuses the existing API key/secret (or OAuth) configuration — no extra auth setup is required.
  • generate returns the upload result (not the generation response) by design, so it behaves as a drop-in for upload with a prompt instead of a file path.
  • Tests follow the existing conventions (sinon stub of https.request, assertions mirroring analyze_spec/debug_mode_spec); no new test utilities were added.

Adds cloudinary.v2.uploader.generate(generateParams, options, callback),
which generates an image from a text prompt and uploads the result in a
single call. It calls the image generation API, then delegates to
uploader.upload using the secure_url from the response, so the resolved
value is the upload result and all standard upload options are honored.

- New internal client call_generate_api (JSON + Basic Auth/OAuth)
- New base_processing_api_url helper for the v2 processing endpoint
- TypeScript types (GenerateImageOptions + generate overloads)
- Tests mirroring existing conventions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant