# Analyze image Extract structured data from images using AI-powered OCR and vision analysis. #### Request Body (multipart/form-data) **`image_file`** file required Image file to analyze. Supported formats: JPEG, PNG, GIF, BMP, TIFF. Max size: 50 MB. **`schema`** string required JSON schema as string defining the structure of data to extract. **`organization_id`** string required Organization ID (org_ prefixed string). **`prompt`** string optional Custom analysis instructions to guide the extraction process. **`model`** string optional Model to use. Values: `gpt-4o` (default), `gpt-4o-mini`. **`provider`** string optional Provider to use. Values: `openai` (default). ## Returns Returns extracted data matching your schema with confidence score and cost information. Receipt Analysis ```bash curl -X POST "https://api.aitronos.com/v1/vision/analyze-image" \ -H "X-API-Key: $FREDDY_API_KEY" \ -F "image_file=@receipt.jpg" \ -F 'schema={"properties":{"merchant":{"type":"string"},"total":{"type":"number"},"date":{"type":"string"},"items":{"type":"array","items":{"type":"object","properties":{"name":{"type":"string"},"price":{"type":"number"}}}}}}' \ -F "organization_id=org_abc123" \ -F "model=gpt-4o" ``` ```python import os import requests import json api_key = os.environ["FREDDY_API_KEY"] schema = { "properties": { "merchant": {"type": "string"}, "total": {"type": "number"}, "date": {"type": "string"}, "items": { "type": "array", "items": { "type": "object", "properties": { "name": {"type": "string"}, "price": {"type": "number"} } } } } } files = {"image_file": open("receipt.jpg", "rb")} data = { "schema": json.dumps(schema), "organization_id": "org_abc123", "model": "gpt-4o" } response = requests.post( "https://api.aitronos.com/v1/vision/analyze-image", headers={"X-API-Key": api_key}, files=files, data=data ) result = response.json() print(f"Merchant: {result['extracted_data']['merchant']}") print(f"Total: ${result['extracted_data']['total']}") ``` ```javascript const FormData = require('form-data'); const fs = require('fs'); const schema = { properties: { merchant: { type: 'string' }, total: { type: 'number' }, date: { type: 'string' }, items: { type: 'array', items: { type: 'object', properties: { name: { type: 'string' }, price: { type: 'number' } } } } } }; const form = new FormData(); form.append('image_file', fs.createReadStream('receipt.jpg')); form.append('schema', JSON.stringify(schema)); form.append('organization_id', 'org_abc123'); form.append('model', 'gpt-4o'); const response = await fetch( 'https://api.aitronos.com/v1/vision/analyze-image', { method: 'POST', headers: { 'Authorization': `Bearer ${process.env.FREDDY_API_KEY}`, ...form.getHeaders() }, body: form } ); const result = await response.json(); console.log(`Merchant: ${result.extracted_data.merchant}`); console.log(`Total: $${result.extracted_data.total}`); ``` Product Label ```bash curl -X POST "https://api.aitronos.com/v1/vision/analyze-image" \ -H "X-API-Key: $FREDDY_API_KEY" \ -F "image_file=@product.jpg" \ -F 'schema={"properties":{"product_name":{"type":"string"},"price":{"type":"number"},"brand":{"type":"string"},"color":{"type":"string"}}}' \ -F "organization_id=org_abc123" \ -F "prompt=Extract product information from the label" ``` ```python import os import requests import json api_key = os.environ["FREDDY_API_KEY"] schema = { "properties": { "product_name": {"type": "string"}, "price": {"type": "number"}, "brand": {"type": "string"}, "color": {"type": "string"} } } files = {"image_file": open("product.jpg", "rb")} data = { "schema": json.dumps(schema), "organization_id": "org_abc123", "prompt": "Extract product information from the label" } response = requests.post( "https://api.aitronos.com/v1/vision/analyze-image", headers={"X-API-Key": api_key}, files=files, data=data ) result = response.json() print(f"Product: {result['extracted_data']['product_name']}") print(f"Brand: {result['extracted_data']['brand']}") print(f"Price: ${result['extracted_data']['price']}") ``` ```javascript const FormData = require('form-data'); const fs = require('fs'); const schema = { properties: { product_name: { type: 'string' }, price: { type: 'number' }, brand: { type: 'string' }, color: { type: 'string' } } }; const form = new FormData(); form.append('image_file', fs.createReadStream('product.jpg')); form.append('schema', JSON.stringify(schema)); form.append('organization_id', 'org_abc123'); form.append('prompt', 'Extract product information from the label'); const response = await fetch( 'https://api.aitronos.com/v1/vision/analyze-image', { method: 'POST', headers: { 'Authorization': `Bearer ${process.env.FREDDY_API_KEY}`, ...form.getHeaders() }, body: form } ); const result = await response.json(); console.log(`Product: ${result.extracted_data.product_name}`); console.log(`Brand: ${result.extracted_data.brand}`); ``` ID Card Scanning ```bash curl -X POST "https://api.aitronos.com/v1/vision/analyze-image" \ -H "X-API-Key: $FREDDY_API_KEY" \ -F "image_file=@id_card.jpg" \ -F 'schema={"properties":{"full_name":{"type":"string"},"id_number":{"type":"string"},"date_of_birth":{"type":"string"},"expiry_date":{"type":"string"},"nationality":{"type":"string"}}}' \ -F "organization_id=org_abc123" \ -F "prompt=Extract all text from the ID card, paying attention to dates in DD/MM/YYYY format" ``` ```python import os import requests import json api_key = os.environ["FREDDY_API_KEY"] schema = { "properties": { "full_name": {"type": "string"}, "id_number": {"type": "string"}, "date_of_birth": {"type": "string"}, "expiry_date": {"type": "string"}, "nationality": {"type": "string"} } } files = {"image_file": open("id_card.jpg", "rb")} data = { "schema": json.dumps(schema), "organization_id": "org_abc123", "prompt": "Extract all text from the ID card, paying attention to dates in DD/MM/YYYY format" } response = requests.post( "https://api.aitronos.com/v1/vision/analyze-image", headers={"X-API-Key": api_key}, files=files, data=data ) result = response.json() print(f"Name: {result['extracted_data']['full_name']}") print(f"ID: {result['extracted_data']['id_number']}") print(f"DOB: {result['extracted_data']['date_of_birth']}") ``` ```javascript const FormData = require('form-data'); const fs = require('fs'); const schema = { properties: { full_name: { type: 'string' }, id_number: { type: 'string' }, date_of_birth: { type: 'string' }, expiry_date: { type: 'string' }, nationality: { type: 'string' } } }; const form = new FormData(); form.append('image_file', fs.createReadStream('id_card.jpg')); form.append('schema', JSON.stringify(schema)); form.append('organization_id', 'org_abc123'); form.append('prompt', 'Extract all text from the ID card, paying attention to dates in DD/MM/YYYY format'); const response = await fetch( 'https://api.aitronos.com/v1/vision/analyze-image', { method: 'POST', headers: { 'Authorization': `Bearer ${process.env.FREDDY_API_KEY}`, ...form.getHeaders() }, body: form } ); const result = await response.json(); console.log(`Name: ${result.extracted_data.full_name}`); console.log(`ID: ${result.extracted_data.id_number}`); ``` **Response:** 200 OK ```json { "success": true, "extracted_data": { "product_name": "Wireless Headphones", "price": 79.99, "brand": "AudioTech", "color": "Black" }, "confidence": 0.92, "cost_chf": 0.018, "model_used": "gpt-4o", "provider": "openai" } ``` 400 Bad Request ```json { "success": false, "error": { "code": "INVALID_SCHEMA", "message": "The provided schema is invalid.", "system_message": "Schema validation failed: missing 'properties' field", "type": "validation_error", "status": 400, "details": { "field": "schema", "issue": "invalid_format" }, "trace_id": "trace_xyz789", "timestamp": "2024-12-16T10:30:00Z" } } ``` 401 Unauthorized ```json { "success": false, "error": { "code": "UNAUTHORIZED", "message": "Authentication required. Please provide a valid API key.", "system_message": "Missing or invalid authorization header", "type": "authentication_error", "status": 401, "trace_id": "trace_abc123", "timestamp": "2024-12-16T10:30:00Z" } } ``` 422 Unprocessable Entity ```json { "success": false, "error": { "code": "INVALID_FILE_TYPE", "message": "The uploaded file type is not supported.", "system_message": "Unsupported image format: .webp", "type": "validation_error", "status": 422, "details": { "file_type": "webp", "supported_types": ["jpg", "jpeg", "png", "gif", "bmp", "tiff"] }, "trace_id": "trace_def456", "timestamp": "2024-12-16T10:30:00Z" } } ``` 500 Server Error ```json { "success": false, "error": { "code": "INTERNAL_SERVER_ERROR", "message": "An unexpected error occurred. Please try again later.", "system_message": "Vision API connection timeout", "type": "server_error", "status": 500, "trace_id": "trace_ghi789", "timestamp": "2024-12-16T10:30:00Z" } } ```