Skip to content
Get started

Step 3: Generate Your First Image (Text-to-Image)

Now that you have authenticated your requests, itโ€™s time to generate your first image. While Scenario offers standard text-to-image endpoints, high-performance third-party models (such as Flux or Imagen) utilize a Custom Generation workflow.

Unlike standard generation, this process is asynchronous. You will submit a request to start a โ€œjob,โ€ receive a Job ID, and then poll the API to retrieve your final image asset.

To generate an image, you will send a POST request to the custom generation endpoint. You must specify a modelId (e.g., model_bfl-flux-2-dev or model_imagen4-ultra) in the URL.

  • Endpoint: POST https://api.cloud.scenario.com/v1/generate/custom/{modelId}
  • Key Parameters:
  • prompt: A detailed description of the image you want.
  • width: The desired width of the image, must be a multiple of 16.
  • height: The desired height of the image, must be a multiple of 16.
import Scenario from '@scenario-labs/sdk';
const client = new Scenario({
apiKey: 'YOUR_API_KEY',
apiSecret: 'YOUR_API_SECRET',
});
const response = await client.generate.runModel('model_bfl-flux-2-dev', {
body: {
prompt:
'A cinematic shot of a futuristic neon city in the rain, hyper-realistic, 8k',
width: 1344,
height: 768,
},
});
console.log(response.job.jobId);

The Response: The API will return a job object containing a jobId.

{
"job": {
"jobId": "job_abcd1234efgh",
"status": "queued"
}
}

Because the image is being processed in the cloud, you need to check the status of your jobId until it is completed.

Endpoint: GET https://api.cloud.scenario.com/v1/jobs/{jobId}

// Option 1: poll manually
const { job } = await client.jobs.retrieve('job_abcd1234efgh');
console.log(job.status);
// Option 2: use the SDK helper to wait until the job reaches a terminal status
const completed = await response.job.wait();
console.log(completed.status);
console.log(completed.metadata?.assetIds);

Keep polling every 2โ€“3 seconds until the status changes from "queued" or "in-progress" to "success".


Once the job status is "success", the jobโ€™s metadata.assetIds array lists the IDs of your generated assets.

Success Response Snippet:

{
"job": {
"jobId": "job_abcd1234efgh",
"status": "success",
"metadata": {
"assetIds": ["asset_xyz123"]
}
}
}

Retrieve each asset to get the URL of its file:

const { asset } = await client.assets.retrieve('asset_xyz123');
console.log(asset.url);

Now that youโ€™ve successfully generated an image using a third-party model, you can:

  • Explore advanced parameters: Check the specific Parameters Reference for the model you are using.
  • List available models: Use GET /v1/models to see which other models you can use.
  • Train your own: Move to Step 4 to learn how to train a model on your own specific art style.