Text to Image API Documentation
Text Validation Endpoint
- Method: POST
- Path:
https://api.kadal.ai/text-to-image/api/v1/text_validation - Summary: Validates input text for suitability in image generation.
Description
This endpoint verifies that the provided text is well-formed and interpretable, ensuring it can be processed effectively to generate a corresponding image.
Request
- Content-Type: multipart/form-data
Payload
| Parameter | Description | Data Type | Is Optional |
|---|---|---|---|
| input_text | Text corresponding to which an image needs to be generated | String | No |
Response
Success (200 OK)
{
"status_code": 200,
"message": "SUCCESS::Text Validation generated successfully",
"input_text": "Your input text result will appear here"
}
Usage
import requests
url = "https://api.kadal.ai/text-to-image/api/v1/text_validation"
token = "your_token_here"
headers = {
"accept": "application/json",
"Authorization": f"Bearer {token}",
"Content-Type": "application/x-www-form-urlencoded",
}
data = {
"input_text": """A paper craft art depicting a girl giving her cat a gentle hug. Both sit amidst potted plants, with the cat purring contentedly while the girl smiles. The scene is adorned with handcrafted paper flowers and leaves."""
}
response = requests.post(url, headers=headers, data=data)
Text to Image Generation Endpoint
- Method: POST
- Path:
https://api.kadal.ai/text-to-image/api/v1/text_to_image - Summary: Generates images from text with configurable count and aspect ratio.
Description
This endpoint generates images from input text using a selected AI model, with options to set the number of images and aspect ratio.
Request
- Content-Type: multipart/form-data
Payload
| Parameter | Description | Data Type | Constraints / Allowed Values | Optional |
|---|---|---|---|---|
| user_model_selection | AI model used for generation | String | Must be one of: dall-e-3 | No |
| input_text | Input text prompt | String | Non-empty; max length: 300 chars | No |
| number_of_images | Number of images to generate | String | Range: 1–3 | No |
| aspect_ratio | Aspect Ratio of images | String | Must be one of: 1:1, 16:9, 9:16 | No |
Response:
{
"status_code": 200,
"message": "SUCCESS::Text to Image generated successfully",
"images_created": {
"image_url_1": "Your image_url will appear here",
"image_url_2": "Your image_url will appear here",
"image_url_3": "Your image_url will appear here"
}
}
Usage
import requests
url = "https://api.kadal.ai/text-to-image/api/v1/text_to_image"
token = "your_token_here"
headers = {
"accept": "application/json",
"Authorization": f"Bearer {token}",
"Content-Type": "application/x-www-form-urlencoded",
}
data = {
"user_model_selection": "dall-e-3",
"input_text": """A paper craft art depicting a girl giving her cat a gentle hug. Both sit amidst potted plants, with the cat purring contentedly while the girl smiles. The scene is adorned with handcrafted paper flowers and leaves.""",
"number_of_images": "3",
"aspect_ratio": "1:1",
}
response = requests.post(url, headers=headers, data=data)
Text to Image Generation Endpoint V2
- Method: POST
- Path:
https://api.kadal.ai/text-to-image/api/v1/text_to_image_v2 - Summary: Generates images from text with configurable count and aspect ratio.
Description
This endpoint generates images from input text using a selected AI model, with options to set the number of images and aspect ratio.
Request
- Content-Type: application/json
Payload
| Parameter | Description | Data Type | Constraints / Allowed Values | Optional |
|---|---|---|---|---|
| provider | AI Provider used for generation | String | Must be one of: azure, vertexai | No |
| model_name | Model used for generation | String | model name of the model | No |
| input_text | Prompt | String | Prompt of the Image | No |
| number_of_images | Number of Images | Integer | Range: 1-4 | No |
| aspect_ratio | Aspect Ratio of images | String | Must be one of: AUTO, SQUARE, LANDSCAPE, PORTRAIT | No |
| base64_images | Base64 of the images | Bool | Must be one of: true, false | Yes (default false) |
Response:
Response Json
{
"status_code": 200,
"message": "Images generated successfully",
"images_created": [
{
"Image_url": "https://learningmate.co/assets/aigenerated/tmp/{tenant_id}/{user_id}/xxxxx.png"
}
],
"text_generated": "Here's a car from the future! "
}
Usage
Example code for curl:
cURL
curl -X 'POST' \
'https://api.kadal.ai/text-to-image/api/v1/text_to_image_v2' \
-H 'accept: application/json' \
-H 'api-key: LM-xxxxx' \
-H 'Content-Type: application/json' \
-d '{
"provider": "vertexai",
"model_name": "gemini-2.5-flash-image",
"input_text": "a car from future",
"number_of_images": 1,
"aspect_ratio": "AUTO",
"base64_images": false
}'
Example code for Python:
Python
import requests
import json
lm_key = "LM-xxxxxxxx" # LM key from you profile
# Define the endpoint URL
url = 'https://api.kadal.ai/text-to-image/api/v1/text_to_image_v2'
# Set up the headers
headers = {
'accept': 'application/json',
'api-key': lm_key,
'Content-Type': 'application/json'
}
# Define the payload (the data you are sending)
data = {
"provider": "vertexai", # Provider
"model_name": "gemini-2.5-flash-image", # Model name
"input_text": "a car from future", # Prompt
"number_of_images": 1, # Number of Image (1-4)
"aspect_ratio": "AUTO", # Ratio: AUTO, SQUARE, LANDSCAPE, PORTRAIT
"base64_images": False # Base_64 of the Images
}
try:
# Make the POST request
response = requests.post(url, headers=headers, json=data)
# Check if the request was successful
response.raise_for_status()
# Parse and print the JSON response
result = response.json()
print(json.dumps(result, indent=4))
except requests.exceptions.HTTPError as http_err:
print(f"HTTP error occurred: {http_err}")
except Exception as err:
print(f"An error occurred: {err}")