> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mixpeek.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Integration Flow: Submit, Check Status, Read

> The three calls an integration makes per item: look it up, submit it once, read its documents. Object states, duplicates, and a typed contract for one retriever.

An integration usually keys everything on its own id, such as a `creative_id` or a `product_sku`. For each item it makes three calls:

1. **Look up** the item's object in the bucket. No object means you never submitted it.
2. **Submit** the item once, only when the lookup finds nothing.
3. **Read** the item's documents once its object is `COMPLETED`.

You keep no state of your own: the lookup tells you where each item stands.

The examples below use a bucket `creatives` whose schema has a `creative_id` string and an `image` blob, and a retriever `creative_lookup` with one input, `creative_id`.

## Object states

An object's `status` tells you where processing stands.

| Status | Meaning | What to do |
| - | - | - |
| `PENDING` | Created, not processed yet | Wait and look it up again |
| `COMPLETED` | Processed. Its documents are searchable | Read its documents |
| `FAILED` | Processing failed. `error` says why | Fix the input and submit again |

Treat any other status as still processing. Combined with the lookup, an item is in one of four states:

| Item state | Lookup returns | Read returns |
| - | - | - |
| Never submitted | `results: []` | `documents: []` |
| Submitted, not ready | One object, `status` not `COMPLETED` or `FAILED` | `documents: []` |
| Ready | One object, `status: "COMPLETED"` | The item's documents |
| Failed | One object, `status: "FAILED"`, `error` set | `documents: []` |

A read alone cannot tell "never submitted" from "not ready", because both return an empty list. The lookup can.

## 1. Look up an item

List the bucket's objects with a filter on your id:

```bash cURL theme={null}
curl -X POST "https://api.mixpeek.com/v1/buckets/creatives/objects/list" \
  -H "Authorization: Bearer $MIXPEEK_API_KEY" \
  -H "X-Namespace: $MIXPEEK_NAMESPACE" \
  -H "Content-Type: application/json" \
  -d '{"filters": {"AND": [{"field": "creative_id", "operator": "eq", "value": "ad_5678"}]}}'
```

```python Python theme={null}
import os, requests

HEADERS = {
    "Authorization": f"Bearer {os.environ['MIXPEEK_API_KEY']}",
    "X-Namespace": os.environ["MIXPEEK_NAMESPACE"],
}
resp = requests.post(
    "https://api.mixpeek.com/v1/buckets/creatives/objects/list",
    headers=HEADERS,
    json={"filters": {"AND": [{"field": "creative_id", "operator": "eq", "value": "ad_5678"}]}},
)
objects = resp.json()["results"]  # [] when the item was never submitted
```

```javascript JavaScript theme={null}
const headers = {
  Authorization: `Bearer ${process.env.MIXPEEK_API_KEY}`,
  "X-Namespace": process.env.MIXPEEK_NAMESPACE,
  "Content-Type": "application/json",
};
const resp = await fetch("https://api.mixpeek.com/v1/buckets/creatives/objects/list", {
  method: "POST",
  headers,
  body: JSON.stringify({
    filters: { AND: [{ field: "creative_id", operator: "eq", value: "ad_5678" }] },
  }),
});
const objects = (await resp.json()).results; // [] when the item was never submitted
```

Each entry in `results` has `object_id`, `status`, `error`, `document_count`, `created_at` and `updated_at`.

## 2. Submit an item

Create the object with `auto_process=true`, so processing starts at once:

```bash cURL theme={null}
curl -X POST "https://api.mixpeek.com/v1/buckets/creatives/objects?auto_process=true" \
  -H "Authorization: Bearer $MIXPEEK_API_KEY" \
  -H "X-Namespace: $MIXPEEK_NAMESPACE" \
  -H "Content-Type: application/json" \
  -d '{
    "creative_id": "ad_5678",
    "blobs": [{"property": "image", "type": "image", "data": "https://example.com/ad_5678.jpg"}]
  }'
```

```python Python theme={null}
resp = requests.post(
    "https://api.mixpeek.com/v1/buckets/creatives/objects",
    params={"auto_process": "true"},
    headers=HEADERS,
    json={
        "creative_id": "ad_5678",
        "blobs": [{"property": "image", "type": "image", "data": "https://example.com/ad_5678.jpg"}],
    },
)
obj = resp.json()  # obj["object_id"], obj["status"] == "PENDING"
```

```javascript JavaScript theme={null}
const created = await fetch(
  "https://api.mixpeek.com/v1/buckets/creatives/objects?auto_process=true",
  {
    method: "POST",
    headers,
    body: JSON.stringify({
      creative_id: "ad_5678",
      blobs: [{ property: "image", type: "image", data: "https://example.com/ad_5678.jpg" }],
    }),
  },
);
const obj = await created.json(); // obj.object_id, obj.status === "PENDING"
```

The response is the object with `status: "PENDING"`. Look it up again until `status` is `COMPLETED` or `FAILED`.

## 3. Read an item's documents

Execute the retriever with your id as its input:

```bash cURL theme={null}
curl -X POST "https://api.mixpeek.com/v1/retrievers/creative_lookup/execute" \
  -H "Authorization: Bearer $MIXPEEK_API_KEY" \
  -H "X-Namespace: $MIXPEEK_NAMESPACE" \
  -H "Content-Type: application/json" \
  -d '{"inputs": {"creative_id": "ad_5678"}}'
```

```python Python theme={null}
resp = requests.post(
    "https://api.mixpeek.com/v1/retrievers/creative_lookup/execute",
    headers=HEADERS,
    json={"inputs": {"creative_id": "ad_5678"}},
)
body = resp.json()
documents, status, warnings = body["documents"], body["status"], body["warnings"]
```

```javascript JavaScript theme={null}
const run = await fetch("https://api.mixpeek.com/v1/retrievers/creative_lookup/execute", {
  method: "POST",
  headers,
  body: JSON.stringify({ inputs: { creative_id: "ad_5678" } }),
});
const { documents, status, warnings } = await run.json();
```

Read `documents`, and check `status` and `warnings` with it. A run that timed out or skipped a stage answers HTTP 200 with `status: "degraded"`, and its `documents` can be short.

You can also read every document made from one object, across all collections, with `GET /v1/objects/{object_id}/documents`.

## Duplicates and retries

Each create makes a new object, even when its fields match an object you created before. Two submits of one item give two objects, two processing charges, and a read that returns the documents of both. You have three ways to prevent it:

| Approach | What it does | When to use it |
| - | - | - |
| Look up before you submit | The flow above. Submit only when the lookup returns nothing | One worker handles each id |
| `idempotency_key` in the create body | A create whose key matches an existing object returns that object | Retrying a create after a timeout |
| A bucket `unique_key` with `policy=insert` | A second create with the same id answers `409 Conflict` | Several workers may submit the same id at once |

`idempotency_key` protects a retry that follows the first call. Two creates with the same key sent at the same moment can both succeed, so use a unique key when submits can race.

### Unique keys

Set `unique_key` when you create the bucket. It cannot be added to a bucket created without one. Its `fields` name the schema fields that identify an item:

```json theme={null}
{
  "bucket_name": "creatives",
  "bucket_schema": {
    "properties": {
      "creative_id": { "type": "string", "required": true },
      "image": { "type": "image" }
    }
  },
  "unique_key": { "fields": ["creative_id"], "default_policy": "insert" }
}
```

The policy decides what a create does when the key exists:

| Policy | Key is new | Key exists |
| - | - | - |
| `insert` | Creates the object | `409 Conflict` |
| `update` | `404 Not Found` | Updates the object |
| `upsert` | Creates the object | Updates the object |

`?policy=` on the create call wins over the bucket's `default_policy`. With neither, the create answers `400`.

## A typed contract for one retriever

The API reference shows the execute call for every retriever, so its document shape is generic. A specific retriever's request and response are fixed by its configuration, and you can read both.

**Request.** `GET /v1/retrievers/{retriever_id}` returns `input_schema`, a flat map of input names to `{"type": ..., "required": ...}`. Those names are the keys of `inputs`:

```json theme={null}
"input_schema": {
  "creative_id": { "type": "string", "required": true }
}
```

**Response.** The same call returns `collection_ids`. `GET /v1/collections/{collection_id}` returns each collection's `output_schema`: the fields its documents carry, which are your passthrough fields plus the extractor's outputs. Stages that enrich or reshape documents add or change fields; each [stage page](https://docs.mixpeek.com/docs/retrieval/stages/feature-search.md) lists what it adds. Every document also has `document_id` and `collection_id`.

From those two reads you can write the types once:

```ts theme={null}
type CreativeLookupRequest = { inputs: { creative_id: string } };

type CreativeLookupResponse = {
  status: string; // "completed", or "degraded" when a stage timed out or was skipped
  warnings: unknown[];
  documents: CreativeDocument[]; // [] until the object is COMPLETED
};

type CreativeDocument = {
  document_id: string;
  collection_id: string;
  creative_id: string; // passthrough field from the bucket
  // ...the extractor and stage output fields from output_schema
};
```

A retriever's shape changes only when you change its stages or its collections. Pin the retriever you integrate against, and re-read both schemas after you edit it.

## Related

* [Buckets and objects](https://docs.mixpeek.com/docs/platform/data-model.md)
* [Filters](https://docs.mixpeek.com/docs/retrieval/filters.md), including `from_object` for an object's documents
* [Retrievers](https://docs.mixpeek.com/docs/retrieval/retrievers.md)
* [Deduplication and re-processing](https://docs.mixpeek.com/docs/processing/deduplication.md)
* [Create object API](https://docs.mixpeek.com/docs/api-reference/bucket-objects/create-object.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.