# merchi.ai API Reference

The merchi.ai API provides programmatic access to AI-powered product content generation and retrieval. Submit products via JSON, CSV, or ZIP archive; receive AI-generated content back via webhooks or the approved products endpoint.

> **Postman collection:** [Run in Postman](https://app.getpostman.com/run-collection/51963753-27edb045-0e1d-43e7-a7c9-f58c77f93f93?action=collection%2Ffork&source=rip_markdown&collection-url=entityId%3D51963753-27edb045-0e1d-43e7-a7c9-f58c77f93f93%26entityType%3Dcollection%26workspaceId%3D4eb1e4b7-c3b7-4a32-b5a5-bd2a4aab6878)

---

## Base URL

```
https://app.merchi.ai/api/functions/v1
```

| Endpoint | Method | Purpose |
|----------|--------|---------|
| `/products` | `POST` | Submit products for AI content generation |
| `/approved-products` | `GET` | Retrieve approved (and rejected) products with generated content |
| `/verify/{generation_id}` | `GET` | Verify AI provenance of generated content (no auth required) |

---

## Authentication

All API requests require an API key. Generate keys in the platform under **Settings → API**.

> **On a free trial?** API and webhook access is not switched on for trial accounts by default. Email [hello@merchi.ai](mailto:hello@merchi.ai) from your trial account's email address and we'll enable both. You can sign up for a trial at [app.merchi.ai/register](https://app.merchi.ai/register).

API keys start with `sk_` and are passed in the `Authorization` header:

```
Authorization: Bearer sk_your_api_key_here
```

Store your API key securely. It provides full access to your workspace's data.

### Naming Your Keys

merchi.ai tracks API usage by the name you give each key. Use descriptive names so the analytics dashboard shows exactly which system called the API and when.

| Key name example | When to use |
|-----------------|-------------|
| `Production` | Your own direct integration |
| `{Partner Name} integration` | A partner calling on your behalf |
| `Shopify connector` | A specific app or connector |
| `Staging` | A test or staging environment |

### X-Source-ID Header (Optional)

If a single partner manages integrations for multiple downstream systems, they can pass the `X-Source-ID` header to identify the originating system on each request. This overrides the key name for that call in the analytics view.

```bash
curl -X POST "https://app.merchi.ai/api/functions/v1/products" \
  -H "Authorization: Bearer sk_your_key_here" \
  -H "X-Source-ID: my-downstream-system-id" \
  -H "Content-Type: application/json" \
  -d '{ ... }'
```

---

## POST /products

Submit products for AI-powered content generation. There are four submission methods across three content types:

| Method | Content-Type | Best For |
|--------|--------------|----------|
| JSON | `application/json` | Direct integrations, image URLs, PDF URLs, web scraping |
| CSV | `multipart/form-data` | Bulk imports of image URLs from spreadsheets |
| ZIP | `multipart/form-data` | Local images and PDFs without URLs |

---

### Method 1: JSON — Image or PDF URLs

Send products with direct image or PDF URLs. merchi.ai downloads and processes the files.

```bash
curl -X POST "https://app.merchi.ai/api/functions/v1/products" \
  -H "Authorization: Bearer sk_your_key_here" \
  -H "Content-Type: application/json" \
  -d '{
    "type": "images",
    "products": [
      {
        "productId": "SKU-001",
        "imageUrl": "https://example.com/images/product1.jpg"
      },
      {
        "productId": "SKU-002",
        "fileUrl": "https://example.com/datasheets/product2.pdf"
      },
      {
        "productId": "SKU-003",
        "imageUrl": "https://example.com/images/product3.jpg",
        "fileUrl": "https://example.com/datasheets/product3.pdf",
        "category": "Electronics",
        "brand": "Acme"
      }
    ]
  }'
```

**Required fields per product** — `productId` and at least one of:

| Field | Type | Description |
|-------|------|-------------|
| `productId` | string | Unique identifier for the product |
| `imageUrl` | string | Publicly accessible URL to a product image |
| `fileUrl` | string | Publicly accessible URL to an image **or** PDF document |

Both `imageUrl` and `fileUrl` may be provided on the same product. `fileUrl` accepts image formats and PDF; type is auto-detected from the URL extension.

**Optional fields per product:**

| Field | Type | Description |
|-------|------|-------------|
| `category` | string | Product category or taxonomy |
| `brand` | string | Brand name |
| `title` | string | Existing title to enhance |
| `description` | string | Existing description |
| `price` | string | Product price |
| Any custom field | any | Additional context for the AI |

**PDF processing:** when `fileUrl` points to a PDF, the full document is sent to the AI for content generation. A preview of the first page is generated as the product thumbnail. PDFs are available on all plans.

---

### Method 2: JSON — Web Scraping

Send product page URLs. merchi.ai visits each page, extracts images and content, then generates enhanced descriptions.

```bash
curl -X POST "https://app.merchi.ai/api/functions/v1/products" \
  -H "Authorization: Bearer sk_your_key_here" \
  -H "Content-Type: application/json" \
  -d '{
    "type": "scrape",
    "products": [
      {
        "productId": "SKU-001",
        "url": "https://example.com/products/blue-widget"
      }
    ]
  }'
```

**Required fields per product:** `productId`, `url`.

Web scraping is only available through JSON requests. CSV uploads are always processed as image URL imports.

---

### Method 3: CSV File Upload

Upload a CSV file of product image and PDF URLs. Ideal for bulk imports from spreadsheets.

```bash
curl -X POST "https://app.merchi.ai/api/functions/v1/products" \
  -H "Authorization: Bearer sk_your_key_here" \
  -F "file=@products.csv"
```

**CSV format:**

```csv
productId,imageUrl,category,brand
SKU-001,https://example.com/img1.jpg,Electronics,Acme
SKU-002,https://example.com/img2.jpg,Clothing,Brand X
SKU-001,https://example.com/img1-side.jpg,Electronics,Acme
```

Rows with the same `productId` are grouped, so one product can have several images. Use `fileUrl` for PDFs — `fileUrl` accepts both PDF and image URLs; type is detected from the file extension.

**Required columns:** `productId` (or `product_id`), and at least one of `imageUrl`/`image_url` or `fileUrl`/`file_url`.

Rows missing a `productId`, or missing both URL columns, are skipped and reported in notifications. A CSV can contain up to **1,000 rows**.

Additional columns are passed as context to improve content generation.

---

### Method 4: ZIP File Upload

Upload a ZIP archive containing product images or PDFs. Use when images are not hosted online.

```bash
curl -X POST "https://app.merchi.ai/api/functions/v1/products" \
  -H "Authorization: Bearer sk_your_key_here" \
  -F "file=@products.zip"
```

**ZIP structure** — the filename (without extension) becomes the `productId`:

```
products.zip
├── SKU-001.jpg         ← image only
├── SKU-002.pdf         ← PDF only
├── SKU-003.png         ← image; pairs with SKU-003.pdf
├── SKU-003.pdf         ← PDF paired with SKU-003 image
└── subfolder/
    └── SKU-004.jpg
```

**Supported images:** JPEG, PNG, WebP, GIF, AVIF, TIFF, BMP. **Documents:** PDF.

---

### Optional: Model Selection

Specify an AI model using the `modelId` parameter (JSON) or `-F "modelId=..."` (file uploads).

| Model | Description |
|-------|-------------|
| `google/gemini-3-flash-preview` | **Default.** Fast, strong at image and PDF understanding |
| `anthropic/claude-sonnet-4.5` | High-quality writing, native PDF support |
| `anthropic/claude-sonnet-5` | Latest Claude Sonnet, native PDF support |
| `openai/gpt-5.1` | Images and text only. Not recommended for PDF documents |

If `modelId` is omitted, the default model is used unless your workspace has a configured default.

---

### POST /products Response

```json
{
  "success": true,
  "jobId": "run_abc123xyz",
  "uploadId": "550e8400-e29b-41d4-a716-446655440000"
}
```

| Field | Description |
|-------|-------------|
| `success` | Boolean — request accepted |
| `jobId` | Job ID for tracking |
| `uploadId` | UUID for this upload batch |

Track job progress via webhooks (recommended), the notifications bell in the platform, the All Products grid, or the approved products endpoint.

Generated content is not returned in this response. Products go to the review queue. Once a product is approved in the platform, its content is delivered by the `product_approved` webhook and returned by `GET /approved-products`.

If you want content without a human review step, ask us to enable auto-approve for your workspace and collect results with `GET /approved-products`. Auto-approved products do not currently fire the `product_approved` webhook.

---

## GET /approved-products

Retrieve approved products with their AI-generated content. Returns the same product data as the `product_approved` webhook — use this endpoint if your integration cannot receive webhooks, or for scheduled batch sync.

```bash
curl -G "https://app.merchi.ai/api/functions/v1/approved-products" \
  -H "Authorization: Bearer sk_your_key_here" \
  --data-urlencode "since=2026-10-01T00:00:00Z" \
  --data-urlencode "limit=50"
```

### Query Parameters

| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| `limit` | integer | `50` | Products per page. 1 to 100. |
| `status` | string | `approved,rejected` | Comma-separated statuses: `approved`, `rejected`, `review`, `pending`. |
| `since` | ISO 8601 | — | Return only products updated after this timestamp, e.g. `2026-10-01T00:00:00Z`. |
| `cursor` | string | — | The `nextCursor` value from a previous response. Takes priority over `since`. |

If you pass neither `since` nor `cursor`, results start from your oldest product — use this for an initial backfill.

### Response

```json
{
  "data": [
    {
      "productId": "SKU-001",
      "output": {
        "en-GB": {
          "title": "Premium Wireless Bluetooth Headphones",
          "description": "Lightweight wireless headphones with 40-hour battery life.",
          "taxonomy": ["Electronics", "Audio", "Headphones"]
        }
      },
      "input": { "productId": "SKU-001", "brand": "AudioTech" },
      "image_paths": [
        {
          "path": "tenant-id/SKU-001/a1b2c3.jpg",
          "url": "https://api.merchi.ai/storage/v1/object/public/processedImages/tenant-id/SKU-001/a1b2c3.jpg"
        }
      ],
      "pdfs": [],
      "workflow_status": "approved",
      "updated_at": "2026-10-14T09:32:11.482913+00:00"
    }
  ],
  "schema": [
    { "label": "Title", "key": "title", "type": "text" }
  ],
  "nextCursor": "eyJ1IjoiMjAyNi0xMC0xNFQwOTozMjoxMS40ODI5MTMrMDA6MDAiLCJpIjo0ODIwfQ",
  "hasMore": false
}
```

| Field | Description |
|-------|-------------|
| `data` | Products, oldest first, ordered by `updated_at` |
| `data[].output` | Generated content keyed by locale. Field keys reflect your schema's Output Name configuration. |
| `data[].input` | Original data submitted with the product |
| `data[].image_paths` | Product images, each with a public `url` |
| `data[].pdfs` | Product PDFs, each with a public `url` |
| `data[].workflow_status` | Current status: `approved`, `rejected`, `review`, or `pending` |
| `data[].updated_at` | ISO 8601 timestamp of last status change |
| `schema` | Your workspace's field labels, keys, and types |
| `nextCursor` | Pass as `cursor` on your next request. Always present, even when `data` is empty. |
| `hasMore` | `true` if more products are available |

### Polling Pattern

1. Make your first call with `since={your_last_sync_timestamp}` (or no parameters for a full backfill)
2. Save `nextCursor`
3. While `hasMore` is `true`, call again immediately with `cursor={nextCursor}`
4. When `hasMore` is `false`, wait for your polling interval, then call again with the saved `nextCursor`

### Handling Changes

- **Rejected products:** if a product you have already imported returns with `workflow_status: "rejected"`, unpublish or remove it.
- **Re-approved products:** a product is returned again if it is edited and re-approved. Update your copy using `productId` as the key.
- **Moved back to review:** products returned to `review` or `pending` are not returned by default. Add those statuses to `status` if you need to track them.

---

## GET /verify/{generation_id}

Verify the AI provenance of any generated product content. No authentication required — anyone with a generation ID can verify independently.

```bash
curl "https://app.merchi.ai/api/functions/v1/verify/11cab0ef-aff1-4ac7-9fd9-0d8ff74e4603"
```

**Response:**

```json
{
  "found": true,
  "app_version": "1.0.0",
  "ai_generated": true,
  "generator": { "model": "google/gemini-3-flash-preview-20251217" },
  "generated_at": "2026-03-07T11:15:21.989Z",
  "review": {
    "human_reviewed": false,
    "review_type": "pending"
  }
}
```

If not found: `{ "found": false }`.

The generation ID is embedded in the `_ai_provenance` block of every product output. See [AI provenance documentation](https://merchi.ai/help/ai-provenance) for details. This supports EU AI Act Article 50 transparency obligations.

---

## HTTP Status Codes

| Code | Meaning |
|------|---------|
| `200` | Request accepted or data returned |
| `400` | Invalid request — missing required fields, bad parameters |
| `401` | Missing or invalid API key |
| `402` | Insufficient credits — upgrade plan or wait for cycle reset |
| `403` | Feature not enabled for this workspace (for example `web_research_not_enabled`) |
| `405` | Method not allowed |
| `415` | Invalid Content-Type |
| `500` | Internal server error, including file uploads rejected by storage (see Limits) |
| `503` | Service temporarily unavailable. Retry with backoff |

---

## Limits

| Limit | Value |
|-------|-------|
| Rows per CSV (image and PDF URL imports) | 1,000 |
| File upload size (CSV or ZIP) | 100 MB |

Uploads over 100 MB are rejected by storage and currently return a `500` with the storage error message, not a dedicated status code. Split large ZIPs into several uploads.

There is no fixed cap on products per JSON request, and the API does not currently enforce per-minute rate limits or return rate limit headers. Each request starts one background job, so for very large catalogues we recommend batches of a few hundred products per request. This keeps webhook job events and failure reports easy to act on.

---

## Credits

Each product processed consumes one credit (two when web research is requested). Credits reset at the start of each billing cycle.

Credits are checked twice:

1. **When the request arrives.** If the workspace has no credits left, the API returns `402 Payment Required` with `{"error": "insufficient_credits"}` and nothing is queued. This check only confirms that at least one credit remains, so a request for more products than you have credits for is still accepted.
2. **As each product is processed.** A product that runs out of credits fails with `Not enough credits`. It is counted in `errorCount` on the `processing_partial` webhook event and is not charged. Products already processed in that job keep their content.

If auto top-up is enabled on your plan, it runs at step 2 before a product is failed.

---

## Common Errors

| Error message | Cause | Fix |
|---------------|-------|-----|
| `Missing Authorization header` | No API key | Add `Authorization: Bearer sk_...` header |
| `Invalid API key` | Key doesn't exist or deleted | Generate a new key in Settings → API |
| `insufficient_credits` | No remaining credits | Upgrade plan or wait for cycle reset |
| `Products array is required` | Empty or missing products | Include at least one product |
| `Each product must have imageUrl or fileUrl` | Missing file URL | Add `imageUrl` or `fileUrl` to each product |
| `Invalid file type` | Wrong file extension | Use `.csv` or `.zip` for file uploads |
| Storage error on upload (`500`) | Upload exceeds 100 MB | Reduce file size or split into smaller uploads |
| `web_research_not_enabled` | Web research requested but not enabled for the workspace | Remove `webResearch` from the request or ask us to enable it |
| `Invalid cursor` | Cursor value was altered | Use `nextCursor` exactly as returned |
| `since must be an ISO 8601 timestamp` | Unparseable `since` value | Use a format such as `2026-10-01T00:00:00Z` |

---

## Related Resources

- [Webhook documentation](https://merchi.ai/webhooks.md) — events, payloads, and configuration
- [OpenAPI spec](https://merchi.ai/openapi.yaml) — machine-readable API definition
- [Schema documentation](https://merchi.ai/help/schema) — configure output fields and Output Names
- [In-app API settings](https://app.merchi.ai/settings/api) — manage API keys
- [AI Agents guide](https://merchi.ai/agents.md) — instructions for AI agent integrations
