Skip to main content
Version: 1.2.0

Alt-Text API Documentation

Version: 1.2.0

Single Image Alt-Text Generation API

/cl/alttext/api/v2/

  • Method: POST
  • Summary: Generate Alt-Text For Single Image
  • Description: Generate alternative text, descriptions, and metadata for a single image file.

Request Payload:

TypeParameterDescriptionData TypeIs Optional
Form DatafileImage file to generate alt text forFile (.png, .jpeg, .jpg, .bmp, .gif)No
Form Dataselected_modelAI model selection (gpt-4o, gpt-4o-mini, gemini-1.5-flash)stringNo
Form Dataalt_text_lengthDesired length of generated alt text (125-500)integerYes
Form Dataalt_promptCustom prompt to guide generationstringYes
Form Datagenerate_descriptionEnable detailed description generationbooleanYes
Form Datagenerate_ocrEnable text extraction from imagebooleanYes
Form DatacontextAdditional context for generationstringYes
Form DataregenerateForce new generation instead of using cachebooleanYes

Sample Code:

import requests

# Input Parameters
api_url = "https://api-genai-dev.learningmate.co/cl/alttext/api/v2/"
image_file_path = "image_file_path"
token = "your_token_here"
selected_model = "gpt-4o" # Options: "gpt-4o", "gpt-4o-mini", "gemini-1.5-flash"
alt_prompt = ""
alt_text_length = 125
generate_description = False
generate_ocr = False
context = ""
regenerate = False

# Headers
headers = {
"Authorization": f"Bearer {token}",
"accept": "application/json"
}

# Prepare the form data
form_data = {
"selected_model": selected_model,
"alt_prompt": alt_prompt,
"alt_text_length": alt_text_length,
"generate_description": str(generate_description).lower(),
"generate_ocr": str(generate_ocr).lower(),
"context": context,
"regenerate": str(regenerate).lower(),
}

try:
# Open the image file and prepare the request
with open(image_file_path, "rb") as image_file:
files = {
"file": (image_file_path, image_file, "multipart/form-data")
}

# Make the POST request
response = requests.post(api_url, headers=headers, data=form_data, files=files)

# Check the response
if response.status_code == 200:
print("Request successful!")
print(response.json())
else:
print(f"Request failed with status code {response.status_code}: {response.text}")

except Exception as e:
print(f"An error occurred: {e}")

Example Response:

{
"status_code": 200,
"message": "Success: Image info generated successfully.",
"file_name": "image_name.extension",
"alt_text": "An alt text for the image.",
"classification": [
"Example classification"
],
"keywords": [
"Keyword 1 ",
"Keyword 2"
],
"description": "An example detailed description of the image.",
"ocr_text": "OCR text extracted from the image."
}

Responses:

Status CodeDescriptionContent-Type
200Successful Response - Image info generated successfullyapplication/json
400Bad Request - Bad Request : Could not process the request due to invalid input, network error or system error. Please try again later or contact support if the issue persists.application/json
401Unauthorized - Invalid or missing authentication tokenapplication/json
415Unauthorized - Error: Invalid file format. Please provide a valid image file format (JPEG, JPG, PNG, BMP, GIF).application/json
422Unprocessable Entity - Content policy violation: Request contains prohibited content. Please try some other contentapplication/json
500Internal Server Error - Request failed: An unexpected error occurred. Please try again later or contact support if the issue persists.application/json

Bulk Alt-Text Generation API

/cl/alttext/api/v3/

  • Method: POST
  • Summary: Generate Alt-Text For Multiple Images
  • Description: Generate alternative text and metadata for multiple images using a ZIP file containing images and configuration.

Request Payload:

TypeParameterDescriptionData TypeIs Optional
Form DatafileZIP file containing images and JSON configurationFile (.zip)No
Query Parameteruser_emailEmail address for receiving resultsstringYes
Query Parametercallback_urlURL for receiving completion notificationstringYes

Sample Code:

import requests

api_url = "https://api-genai-dev.learningmate.co/cl/alttext/api/v3/"
zip_file_path = "path/to/your/images.zip"
token = "your_access_token"
user_email = "user@example.com"
callback_url = "https://your-callback-url.com/callback"

headers = {
"Authorization": f"Bearer {token}",
"accept": "application/json"
}

params = {
"user_email": user_email,
"callback_url": callback_url
}


try:
with open(zip_file_path, "rb") as zip_file:
files = {
"file": (zip_file_path, zip_file, "application/x-zip-compressed")
}
response = requests.post(api_url, headers=headers, params=params, files=files)

if response.status_code == 200 or response.status_code == 202:
print("Request successful!")
print(response.json())
else:
print(f"Request failed with status code {response.status_code}: {response.text}")

except Exception as e:
print(f"An error occurred: {e}")

Example Response:

{
"job_id": "12345",
"s3_url": "S3 url for uploaded input zip file",
"status": "Queued",
"message": "Job is queued for processing. Please check the job status with the status api using job_id"
}

Responses:

Status CodeDescriptionContent-Type
200Successful Response - Job submitted successfullyapplication/json
400Bad Request - Unsupported file type. Only .zip files are supportedapplication/json
401Unauthorized - Invalid or missing authentication tokenapplication/json
415Unsupported Media Type - Unsupported Media Type: Only .zip files are supportedapplication/json
422Validation Error - No Json File in the ZIPapplication/json
422Validation Error - No image Files in the ZIPapplication/json
422Validation Error - Too many image Files in the ZIPapplication/json
422Validation Error - Too many Json Files in the ZIPapplication/json
500Internal Server Error - Unexpected server errorapplication/json

Status Check API

/cl/alttext/api/v3/status/{job_id}

  • Method: GET
  • Summary: Check Status of Bulk Alt-Text Generation Job
  • Description: Retrieve the current status and results of a bulk processing job.

Request Payload:

TypeParameterDescriptionData TypeIs Optional
Path Parameterjob_idUnique identifier for the bulk processing jobstringNo

Sample Code:

import requests

job_id = "12345"
api_url = f"https://api-genai-dev.learningmate.co/cl/alttext/api/v3/status/{job_id}"
token = "your_access_token"

headers = {
"Authorization": f"Bearer {token}",
"accept": "application/json"
}

try:
response = requests.get(url, headers=headers)

if response.status_code == 200:
print("Job status retrieved successfully!")
print(response.json())
elif response.status_code == 404:
print(f"Job not found: {response.json().get('detail', 'No additional details')}")
else:
print(f"Request failed with status code {response.status_code}: {response.text}")

except Exception as e:
print(f"An error occurred: {e}")

Example Response:

{
"job_id": "3c22c4a3-bcfa-4dad-a55c-8e144fcd582e",
"status": "Completed",
"file_name": "zip_filename.zip",
"s3_url": "S3 link for input file ",
"created_at": "2025-01-03T07:44:30.616000",
"updated_at": "2025-01-03T07:44:36.088000",
"result": {
"status_code": 200,
"message": "Success: Image information for zip file generated successfully.",
"total_images": 2,
"success_count": 1,
"failure_count": 1,
"cdn_url": "S3 link for output file ",
"images": [
{
"status": "success",
"message": "Successfully generated image info",
"name": "imagename.extension",
"file_ref": "Images/image_2.extension",
"alt_text": "An Amazon receipt showing details of a purchase including the seller's information, buyer's address, invoice date, payment method, and itemized list of purchased products with prices.",
"classification": "Image Classification",
"keywords": ["keyword 1, keyword 2, keyword 3, ... "],
"long_alt_text": ""
},
{
"status": "failure",
"message": "Failed to generate image info",
"name": "image_name",
"file_ref": "Images/image_name",
"alt_text": "",
"classification": "",
"keywords": []
}
]
}
}

Responses:

Status CodeDescriptionContent-Type
200Successful Response - Status retrieved successfullyapplication/json
400Bad Request - Invalid job ID formatapplication/json
401Unauthorized - Invalid or missing authentication tokenapplication/json
404Job not found - Job with job_id 12345 not found.application/json
422Validation Error - Invalid job_id format. Please provide a valid job_id.application/json
500Internal Server Error - An error occurred while fetching the job status: [error details].application/json