Using Text-to-Image Models
Once you've deployed an text-to-image model on RunGen.AI, you can start generating images. This guide will walk you through accessing the models programatically after experimenting on the playground (see last article).
1. Prerequisites
Before you begin, ensure you have:
- A deployed text-to-image model on RunGen.AI
- Your API key (Check the API key guide if you need help finding it)
- The app ID of your deployed model
2. Sending an Image for Processing
To generate an image from your prompt, you need to send a request to the Run Job endpoint. This request is asynchronous, meaning the model will process the prompt, and you'll retrieve the result later.
Endpoint
POST https://api.rungen.ai/app/{app_id}/run_async
Required Headers
Header | Description |
---|---|
x-api-key | Your API key for authentication |
Content-Type | application/json |
Request Body
{
"input": {
"prompt": "A futuristic city at sunset",
"height": 1024,
"width": 1024
}
}
Example Request Using cURL
curl --location 'https://api.rungen.ai/app/{app_id}/run_async' \
--header 'x-api-key: your_api_key' \
--header 'Content-Type: application/json' \
--data '{
"input": {
"prompt": "A futuristic city at sunset",
"height": 1024,
"width": 1024
}
}'
Response
If the request is successful, you will receive a job ID, which you will use to check the status and retrieve the results.
{
"job_id": "b25b4fc9-dc3b-4c2f-bcf8-09b5d3c7ef12",
"status": "QUEUED"
}
Step 3: Retrieve the Generated Image
Once the job is submitted, you'll receive a job_id
. Use it to check the job status and retrieve the generated image.
Check Job Status
GET https://api.rungen.ai/app/{app_id}/job/{job_id}
Example Response
{
"data": {
"status": "COMPLETED",
"result": {
"images": [
{
"image": "https://..."
}
]
}
}
}
The image
field contains a URL to the generated image, which you can download or use in your application.
4. Next Steps
- Experiment with different images in the Playground.
- Integrate the API into your application.
- Review the API documentation for more advanced use cases.
For any questions, reach out to our support team.