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.
1. Initiate the Generation
Section titled β1. Initiate the Generationβ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.
The Request
Section titled βThe Requestβ- 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.
Example β TypeScript:
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.id);Example β Python:
from scenario_sdk import Scenario
client = Scenario( api_key="YOUR_API_KEY", api_secret="YOUR_API_SECRET",)
response = client.generate.run_model( "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, },)
print(response.job.id)Example β cURL:
curl -X POST "https://api.cloud.scenario.com/v1/generate/custom/model_bfl-flux-2-dev" \ -u "YOUR_API_KEY:YOUR_API_SECRET" \ -H "Content-Type: application/json" \ -d '{ "prompt": "A cinematic shot of a futuristic neon city in the rain, hyper-realistic, 8k", "width": 1344, "height": 768, }'The Response:
The API will return a job object containing a jobId.
{ "job": { "id": "job_abcd1234efgh", "status": "queued" }}2. Poll for the Result
Section titled β2. Poll for the Resultβ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}
Example β TypeScript:
// Option 1: poll manuallyconst 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 statusconst completed = await response.job.wait();console.log(completed.status);console.log(completed.metadata?.assetIds);Example β Python:
import time
while True: job = client.jobs.retrieve("job_abcd1234efgh") if job.status in ("success", "failure", "canceled"): break time.sleep(2)
print(job.status)Example β cURL:
curl -u "YOUR_API_KEY:YOUR_API_SECRET" \ "https://api.cloud.scenario.com/v1/jobs/job_abcd1234efgh"Keep polling every 2β3 seconds until the status changes from "queued" or "in-progress" to "success".
3. Retrieve Your Image
Section titled β3. Retrieve Your ImageβOnce the job status is "success", the response will include an images array (or result object) containing the URL of your generated asset.
Success Response Snippet:
{ "job": { "id": "job_abcd1234efgh", "status": "success", "result": { "images": [ { "url": "https://media.scenario.com/assets/asset_xyz123.png" } ] } }}Whatβs Next?
Section titled βWhatβs Next?β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/modelsto 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.