---
title: Analyze image
description: Extract structured data from images using AI-powered OCR
keywords:
  - image analysis
  - OCR
  - data extraction
  - vision API
---

# Analyze image

Extract structured data from images using AI-powered OCR and vision analysis.

{% api-container %}
{% api-content %}

{% endpoint method="POST" path="https://api.aitronos.com/v1/vision/analyze-image" /%}

#### Request Body (multipart/form-data)

**`image_file`** file <em style="color: #ef4444 !important; font-weight: 600 !important; font-style: normal !important;">required</em>

Image file to analyze. Supported formats: JPEG, PNG, GIF, BMP, TIFF. Max size: 50 MB.

**`schema`** string <em style="color: #ef4444 !important; font-weight: 600 !important; font-style: normal !important;">required</em>

JSON schema as string defining the structure of data to extract.

**`organization_id`** string <em style="color: #ef4444 !important; font-weight: 600 !important; font-style: normal !important;">required</em>

Organization ID (org_ prefixed string).

**`prompt`** string <em style="color: #9ca3af !important; font-weight: 500 !important; font-style: normal !important;">optional</em>

Custom analysis instructions to guide the extraction process.

**`model`** string <em style="color: #9ca3af !important; font-weight: 500 !important; font-style: normal !important;">optional</em>

Model to use. Values: `gpt-4o` (default), `gpt-4o-mini`.

**`provider`** string <em style="color: #9ca3af !important; font-weight: 500 !important; font-style: normal !important;">optional</em>

Provider to use. Values: `openai` (default).

## Returns

Returns extracted data matching your schema with confidence score and cost information.

{% /api-content %}
{% api-examples %}
{% tabs %}
{% tab label="Receipt Analysis" %}

{% code-group mode="dropdown" %}
```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: {
      'X-API-Key': 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}`);
```
{% /code-group %}

{% /tab %}
{% tab label="Product Label" %}

{% code-group mode="dropdown" %}
```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: {
      'X-API-Key': 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}`);
```
{% /code-group %}

{% /tab %}
{% tab label="ID Card Scanning" %}

{% code-group mode="dropdown" %}
```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: {
      'X-API-Key': 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}`);
```
{% /code-group %}

{% /tab %}
{% /tabs %}

**Response:**

{% tabs %}
{% tab label="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"
}
```

{% /tab %}
{% tab label="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"
  }
}
```

{% /tab %}
{% tab label="401 Unauthorized" %}

```json
{
  "success": false,
  "error": {
    "code": "AUTHENTICATION_REQUIRED",
    "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",
    "details": {}
  }
}
```

{% /tab %}
{% tab label="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"
  }
}
```

{% /tab %}
{% tab label="500 Server Error" %}

```json
{
  "success": false,
  "error": {
    "code": "INTERNAL_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",
    "details": {}
  }
}
```

{% /tab %}
{% /tabs %}
{% /api-examples %}
{% /api-container %}

---

## Related Resources

- [Extract Document](./extract.md)
