ImgStory API Documentation

Welcome to the ImgStory API documentation. This API allows you to analyze media files (images and videos) and generate creative stories based on visual content using OpenAI's vision models.

Quick Start

The easiest way to get started is to use our web interface at the homepage. For direct API access, see the endpoint documentation below.

Base URL

http://localhost:8000

For production environments, replace with your actual domain.

Authentication

Currently, the ImgStory API does not require authentication for local usage. If deploying to production, you may want to implement authentication using API keys or OAuth2 to secure your endpoints.

Rate Limits

This application relies on OpenAI's API which has its own rate limits. Please be mindful of the following:

  • There may be limits on the number of requests you can make within a time period
  • Token usage is tracked and displayed in the response
  • Processing large video files may take more time than images

API Endpoints

GET /

Serves the main HTML interface for the application.

Response

Returns the HTML page for interacting with the API through a user interface.

Status Codes

Status Code Description
200 OK - The request was successful
GET /api/docs

Serves the API documentation (this page).

Response

Returns HTML documentation about API endpoints and usage.

Status Codes

Status Code Description
200 OK - The request was successful
POST /analyze/

Processes uploaded media files and generates creative stories in both English and Thai.

Request

This endpoint accepts multipart/form-data with the following parameters:

Parameter Type Required Description
files File(s) Yes Media files to analyze. Supports JPG, PNG images (multiple files allowed) or a single MP4 video. Maximum file size: 10MB per image, 50MB for video.
prompt String No Optional text prompt to guide the story generation. If not provided, a default prompt will be used.

Response

Returns a JSON object with the following properties:

{
  "english": "English language story generated from the media",
  "thai": "Thai language translation of the story",
  "token_usage": {
    "input_tokens": 123,
    "output_tokens": 456,
    "total_tokens": 579
  }
}
cURL
JavaScript
Python
curl -X POST http://localhost:8000/analyze/ \
  -F "files=@/path/to/your/image.jpg" \
  -F "prompt=Generate a story about this image in the style of Anthony Bourdain"
const formData = new FormData();
formData.append('files', imageFile); // From file input
formData.append('prompt', 'Generate a story about this image in the style of Anthony Bourdain');

fetch('http://localhost:8000/analyze/', {
  method: 'POST',
  body: formData
})
.then(response => response.json())
.then(data => {
  console.log(data.english); // English story
  console.log(data.thai);    // Thai story
  console.log(data.token_usage); // Token usage statistics
})
.catch(error => console.error('Error:', error));
import requests

url = "http://localhost:8000/analyze/"
files = {'files': open('image.jpg', 'rb')}
data = {'prompt': 'Generate a story about this image in the style of Anthony Bourdain'}

response = requests.post(url, files=files, data=data)
result = response.json()

print(result['english'])
print(result['thai'])
print(result['token_usage'])

Status Codes

Status Code Description
200 OK - The request was successful
400 Bad Request - Invalid file type, file size exceeds limits, or other client errors
422 Unprocessable Entity - The server understands the content type but was unable to process the contained instructions
429 Too Many Requests - Rate limit exceeded with the OpenAI API
500 Internal Server Error - Something went wrong on the server side
503 Service Unavailable - The OpenAI API is temporarily unavailable

Error Handling

The API returns standard HTTP status codes to indicate the success or failure of a request. Error responses include a JSON object with details about what went wrong.

Error Response Format

{
  "detail": "Error message describing what went wrong"
}

Usage Examples

Analyzing a Single Image

This example demonstrates how to upload a single image and generate a story:

curl -X POST http://localhost:8000/analyze/ \
  -F "files=@/path/to/your/image.jpg"

Analyzing Multiple Images

You can upload multiple images in a single request:

curl -X POST http://localhost:8000/analyze/ \
  -F "files=@/path/to/image1.jpg" \
  -F "files=@/path/to/image2.jpg" \
  -F "files=@/path/to/image3.jpg"

Analyzing a Video

You can also upload a video file:

curl -X POST http://localhost:8000/analyze/ \
  -F "files=@/path/to/video.mp4"

Troubleshooting

If you encounter issues using the API, check the following:

  • Ensure you're using supported file formats (JPG, PNG for images, MP4 for video)
  • Check file size limits (10MB for images, 50MB for video)
  • For server-side issues, check the application logs
  • If you encounter rate limiting, wait and try again later

Common Issues

File Too Large

If you receive a 400 Bad Request error, your file may exceed the size limit. Try compressing your images or videos before uploading.

Rate Limiting

If you receive a 429 Too Many Requests error, you've exceeded the OpenAI API rate limits. Wait a few minutes before trying again.