> ## 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.

# Streams, databases and the web

> Ingest RTSP camera streams, PostgreSQL and Snowflake tables, HTTP APIs, RSS feeds, Bright Data datasets, Instagram, TikTok and email into a bucket.

Bring rows, feed entries, camera segments, social posts and emails into a [bucket](https://docs.mixpeek.com/docs/ingest/buckets.md) with the same two calls you use for object storage: a **storage connection** holds the credentials, and a **sync** on the bucket says what to read and how often. Each row, entry, segment, post or email becomes one object.

| Source | `provider_type` | One object per | `source_path` |
| - | - | - | - |
| [RTSP camera or encoder](#rtsp-camera-streams) | `rtsp` | Video segment | The stream path, such as `/stream1` |
| [PostgreSQL](#postgresql) | `postgresql` | Row, or a Parquet slice of rows | `table` or `schema.table` |
| [Snowflake](#snowflake) | `snowflake` | Row | `TABLE` or `DATABASE.SCHEMA.TABLE` |
| [HTTP API](#http-api) | `http_api` | Item in the JSON response | The full URL |
| [RSS or Atom feed](#rss-and-atom-feeds) | `rss` | Feed entry | The feed URL |
| [Bright Data](#bright-data) | `brightdata` | Dataset record | The dataset ID, `gd_...` |
| [Instagram](#instagram) | `instagram` | Post, reel or carousel | The target account's username |
| [TikTok](#tiktok) | `tiktok` | Video | `/` |
| [Email](#email) | `email` | Email, with attachments as blobs | Any label, such as `inbox` |

## Prerequisites

* A bucket whose schema declares the fields and blobs the source writes. See [Bucket schema](https://docs.mixpeek.com/docs/ingest/buckets.md#bucket-schema).
* An API key with the **`admin`** permission to create the connection. Syncs need `write`.
* Network access from Mixpeek to the database, camera or API host.

The connection and sync calls, sync options (`sync_mode`, `polling_interval_seconds`, `file_filters`, `schema_mapping`, `reconcile`), monitoring and the dead-letter queue are the same for every provider and are covered in [Object storage and syncs](https://docs.mixpeek.com/docs/ingest/object-storage.md). This page covers what differs per source.

## Connect a source

The example syncs a PostgreSQL table. For any other source, change `provider_type`, `provider_config` and `source_path` as the sections below describe.

**1. Create the connection**

```bash cURL theme={null}
curl -X POST "https://api.mixpeek.com/v1/organizations/connections" \
  -H "Authorization: Bearer $MIXPEEK_API_KEY" \
  -H "Content-Type: application/json" \
  -d @- <<EOF
{
  "name": "production-postgres",
  "provider_type": "postgresql",
  "provider_config": {
    "credentials": {"type": "username_password", "username": "mixpeek_sync", "password": "$PG_PASSWORD"},
    "host": "$PG_HOST",
    "database": "production",
    "ssl_mode": "require",
    "incremental_column": "updated_at",
    "primary_key_columns": ["id"]
  }
}
EOF
```

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

conn = requests.post(
    "https://api.mixpeek.com/v1/organizations/connections",
    headers={"Authorization": f"Bearer {os.environ['MIXPEEK_API_KEY']}"},
    json={
        "name": "production-postgres",
        "provider_type": "postgresql",
        "provider_config": {
            "credentials": {
                "type": "username_password",
                "username": "mixpeek_sync",
                "password": os.environ["PG_PASSWORD"],
            },
            "host": os.environ["PG_HOST"],
            "database": "production",
            "ssl_mode": "require",
            "incremental_column": "updated_at",
            "primary_key_columns": ["id"],
        },
    },
).json()
print(conn["connection_id"])
```

```javascript JavaScript theme={null}
const conn = await (
  await fetch("https://api.mixpeek.com/v1/organizations/connections", {
    method: "POST",
    headers: {
      Authorization: `Bearer ${process.env.MIXPEEK_API_KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      name: "production-postgres",
      provider_type: "postgresql",
      provider_config: {
        credentials: {
          type: "username_password",
          username: "mixpeek_sync",
          password: process.env.PG_PASSWORD,
        },
        host: process.env.PG_HOST,
        database: "production",
        ssl_mode: "require",
        incremental_column: "updated_at",
        primary_key_columns: ["id"],
      },
    }),
  })
).json();
console.log(conn.connection_id);
```

**2. Create the sync and run it**

```bash cURL title="Sync the customers table every 30 minutes" theme={null}
curl -X POST "https://api.mixpeek.com/v1/buckets/$BUCKET_ID/syncs" \
  -H "Authorization: Bearer $MIXPEEK_API_KEY" \
  -H "X-Namespace: $NAMESPACE_ID" \
  -H "Content-Type: application/json" \
  -d @- <<EOF
{"connection_id": "$CONNECTION_ID", "source_path": "public.customers", "polling_interval_seconds": 1800}
EOF
```

Then `POST /v1/buckets/$BUCKET_ID/syncs/$SYNC_ID/trigger` for the first pass, or wait one interval.

To check it worked, test the connection with `POST /v1/organizations/connections/$CONNECTION_ID/test`, then read the sync's `total_files_synced` and the bucket's objects as described in [Check that it worked](https://docs.mixpeek.com/docs/ingest/object-storage.md#check-that-it-worked).

## RTSP camera streams

One connection is one camera or encoder. Each sync run opens the stream, captures `segment_seconds × segments_per_run` seconds, cuts it into segments, and closes it. Each segment becomes one object.

Capture is windowed. Footage between runs is not kept, so an RTSP connection samples a stream and does not archive it. Coverage is `segment_seconds × segments_per_run ÷ polling_interval_seconds`:

| Poll interval | `segment_seconds` | `segments_per_run` | Captured | Stream held open |
| - | - | - | - | - |
| 300 s | 30 | 1 | 10% | 39 s |
| 300 s | 30 | 5 | 50% | 159 s |
| 300 s | 30 | 9 | 90% | 279 s |

Each run adds about 9.4 seconds of setup. Keep capture plus setup under `polling_interval_seconds`, or runs overlap; that caps coverage at about 97% on a 300-second interval and 84% on a 60-second one.

```json title="provider_config" theme={null}
{
  "url": "rtsp://camera.example.com:554/stream1",
  "credentials": {"type": "basic", "username": "admin", "password": "CAMERA_PASSWORD"},
  "transport": "tcp",
  "segment_seconds": 30,
  "segments_per_run": 2
}
```

| Field | Default | Notes |
| - | - | - |
| `url` | Required | `rtsp://` or `rtsps://` only. A URL with `user:pass@` is rejected; put credentials in `credentials` |
| `transport` | `tcp` | `tcp` survives NAT and firewalls. Use `udp` when the camera handles interleaved TCP badly |
| `segment_seconds` | `30` | 5 to 300. A target: cuts land on keyframes, so 10-second requests on a 3-second keyframe camera gave 9 to 12 seconds |
| `segments_per_run` | `1` | 1 to 20 |
| `connect_timeout_seconds` | `15` | 5 to 120. The connection test fails if the stream does not start in time |

Capture cost does not depend on segment length, because capture copies the stream without re-encoding. The cost that scales is downstream: each segment is one object and one pipeline run. Shorter segments give a first result sooner (about `segment_seconds` + 9.4 seconds + pipeline time).

**Map the segment to your blob field.** Without a `schema_mapping`, segments land on the default blob property `content`, and a collection reading another property processes nothing while reporting success. Use the `rtsp_field` source for capture and gate values: `source_url`, `segment_index`, `segment_duration_seconds`, `captured_at`, `transport`, `applied`, `top_score`, `match_count` and `error`.

```json title="Sync schema_mapping for RTSP" theme={null}
{
  "connection_id": "conn_abc123",
  "source_path": "/stream1",
  "polling_interval_seconds": 60,
  "schema_mapping": {
    "mappings": {
      "segment": {"target_type": "blob", "blob_property": "segment", "blob_type": "video", "source": {"type": "file"}},
      "captured_at": {"target_type": "field", "source": {"type": "rtsp_field", "field": "captured_at"}},
      "gate_applied": {"target_type": "field", "source": {"type": "rtsp_field", "field": "applied"}}
    }
  }
}
```

> [accordion] Drop segments that do not matter
>
> Two filters run on each segment, cheapest first.
>
> `scene_change_threshold` (0 to 64) compares a 64-bit perceptual hash of the segment's first frame with the last kept segment and drops it when the Hamming distance is at or below the value. `0` drops only identical frames; `5` allows for compression noise.
>
> A gate then judges each remaining segment. Set one of:
>
> | Field | The gate |
> | - | - |
> | `gate_retriever_id` | A saved [retriever](https://docs.mixpeek.com/docs/retrieve/retrievers.md). The segment is its query; the segment is kept when it returns a result, or a top score at or above `gate_retriever_min_score` |
> | `gate_inference_name` | A real-time inference plugin that returns `keep` plus any fields to store |
>
> `gate_on_error` (`publish` by default, or `drop`) decides what happens when the gate fails or times out. A dropped live segment cannot be recaptured. Keep `gate_timeout_seconds` (default 30) well below the capture window. Map `applied` to a field: `false` marks a segment the gate could not judge, which otherwise looks the same as one it passed.

> [accordion] Alert on what the gate kept
>
> Once gate values are fields on the object, a retriever filtered on `gate_top_score` or `gate_match_count` selects confident matches, and an [alert](https://docs.mixpeek.com/docs/enrich/alerts-and-triggers.md) on that retriever fires only for them. A filter on `provider = rtsp` matches every segment and fires constantly. If an alert's `batch` channel feeds a collection, set `batch_collection_ids` on the sync so the sync does not also feed that collection.

## PostgreSQL

Each row becomes one JSON object. The same connection backs the `sql_lookup` [retriever stage](https://docs.mixpeek.com/docs/retrieve/stages.md), which reads PostgreSQL during a query. Requires PostgreSQL 12 or later and a role with `CONNECT` on the database, `USAGE` on the schema and `SELECT` on the tables.

```sql title="Read-only role" theme={null}
CREATE ROLE mixpeek_sync LOGIN PASSWORD 'choose-a-strong-password';
GRANT CONNECT ON DATABASE production TO mixpeek_sync;
GRANT USAGE ON SCHEMA public TO mixpeek_sync;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO mixpeek_sync;
```

| Field | Default | Notes |
| - | - | - |
| `host`, `database`, `credentials` | Required | `credentials.type` is `username_password` |
| `port` | `5432` | |
| `schema` | `public` | `source_path` can override it as `schema.table`. Three dot-separated parts fail validation |
| `ssl_mode` | `prefer` | `disable`, `allow`, `prefer`, `require`, `verify-ca`, `verify-full` |
| `incremental_column` | None | A `TIMESTAMP` or `DATE` column. Each run reads rows above the highest value seen |
| `primary_key_columns` | None | Gives each row a stable object ID. Without it, a re-read can create a second object for the same row |
| `query_timeout_seconds`, `fetch_size` | `300`, `1000` | |

Every reading session runs with `default_transaction_read_only = on`.

> [accordion] Bulk import, embedding columns and change capture
>
> For a large table, or one with a `vector` or `halfvec` column, set `provider_filters.import` on the sync. The table is read in primary-key slices, each slice lands as one Parquet object, and each row becomes one document whose ID derives from the table and primary key, so re-runs update the same document.
>
> ```json title="provider_filters.import" theme={null}
> {
>   "import": {
>     "mode": "slices",
>     "slice_rows": 20000,
>     "objects_per_batch": 4,
>     "text_column": "caption",
>     "vector_columns": {"embedding": {"model": "text-embedding-3-large", "dimensions": 3072, "mode": "carry"}},
>     "replication": "logical",
>     "publication": "mixpeek_pub"
>   }
> }
> ```
>
> * `vector_columns` mode `carry` stores the vector with no embedding call; `reextract` embeds `text_column` instead. A carried vector whose model or dimension differs from the collection's feature is refused at sync create.
> * `replication: logical` creates a replication slot, copies the slices inside its snapshot, then streams inserts, updates and deletes. It needs `wal_level = logical`, a role with `REPLICATION` connecting directly (no transaction-mode PgBouncer), and a publication: `CREATE PUBLICATION mixpeek_pub FOR TABLE public.scenes;`. Set `max_slot_wal_keep_size` so a stalled slot cannot fill the disk. A slot paused 24 hours is dropped; deleting the sync drops it too.
> * `replication: polling` reads rows whose `updated_at` moved and misses hard deletes. `none` imports once.
> * A column starting with `_` or named like a field Mixpeek writes (`metadata`, `text`, `data`, `document_id`, `collection_id`, `mime_type`) is refused. Import a view that renames it, with `key_columns` naming the view's key. Views cannot use logical replication.

## Snowflake

Each table row becomes one object, with incremental sync on a watermark column.

```json title="provider_config" theme={null}
{
  "credentials": {"type": "key_pair", "username": "MIXPEEK_SYNC", "private_key": "-----BEGIN PRIVATE KEY-----\nKEY\n-----END PRIVATE KEY-----\n"},
  "account": "xy12345.us-east-1",
  "warehouse": "MIXPEEK_SYNC_WH",
  "database": "PRODUCTION",
  "schema": "PUBLIC",
  "role": "SYNC_ROLE",
  "incremental_column": "updated_at",
  "primary_key_columns": ["id"]
}
```

`credentials.type` is `key_pair` (with optional `private_key_passphrase`) or `username_password`. The role needs `USAGE` on the warehouse, database and schema and `SELECT` on the table. Without `incremental_column`, every run scans the whole table. Use a dedicated warehouse to keep sync cost separate.

The [`sql_lookup`](https://docs.mixpeek.com/docs/retrieve/stages#sql-lookup) stage reads PostgreSQL only. To join Snowflake values onto results at query time, use the [`api_call`](https://docs.mixpeek.com/docs/retrieve/stages#api-call) stage against an endpoint that queries Snowflake.

## Export to Snowflake or Databricks

Mixpeek has no Databricks connector. To get extracted features into Snowflake or Databricks for SQL analytics, BI and model training, read documents from a collection and load them on your side: Snowflake `COPY INTO` or Snowpipe, or Databricks Auto Loader into Delta tables. An [alert or webhook](https://docs.mixpeek.com/docs/enrich/alerts-and-triggers.md) on batch completion can start the load.

## HTTP API

Polls any JSON or JSONL endpoint and creates one object per item, with the item's JSON as the blob. Items whose ID already exists are skipped unless the sync sets `skip_duplicates: false`.

```json title="provider_config" theme={null}
{
  "credentials": {"type": "http_headers", "headers": {"Authorization": "Bearer API_TOKEN"}},
  "items_path": "data.orders",
  "item_id_field": "order_id",
  "item_modified_field": "updated_at"
}
```

| Field | Default | Notes |
| - | - | - |
| `item_id_field` | Required | Unique, stable field used to deduplicate |
| `items_path` | Root | Dot path to the array, such as `data.results`. A number indexes a list: `products.0.files` |
| `item_modified_field` | None | ISO 8601 or epoch timestamp. Each run requests only newer items |
| `http_method`, `request_body` | `GET`, None | `POST` with a JSON body is supported |
| `response_content_type` | `json` | Or `jsonl` |
| `request_timeout`, `max_retries` | `30`, `3` | Retries cover 429, 5xx and truncated responses |
| `pagination` | None | `next_path` (cursor or next URL, with `cursor_param` for a cursor) or `offset_param` with `limit_param` and `page_size`. `max_pages` defaults to 1,000 |

`source_path` is the full URL.

## RSS and Atom feeds

Each entry becomes one object, and entries already seen are skipped. A public feed needs an empty `provider_config`; a private one takes `{"credentials": {"type": "http_headers", "headers": {"Authorization": "Bearer FEED_TOKEN"}}}`. One connection serves many feeds: create one sync per feed URL, with the URL as `source_path`. Feeds are fetched in full on each poll. Map entry values with the `rss_field` schema mapping source.

## Bright Data

Each sync run triggers a new snapshot of a Bright Data dataset, waits for it to be ready, and creates one object per record. The record's JSON is the blob, and its top-level string, number and boolean fields become object metadata. Records are deduplicated across runs by `<snapshot_id>:<record_id>`.

```json title="provider_config" theme={null}
{"credentials": {"type": "api_token", "api_token": "BRIGHTDATA_TOKEN"}, "default_output_format": "jsonl", "country": "us"}
```

`source_path` is the dataset ID from the Bright Data marketplace, starting with `gd_`. `country` (ISO 3166-1 alpha-2) narrows collection to one country. A snapshot can take from minutes to an hour, and snapshots expire after 1 hour by default, so a large dataset may need geo-targeting or a higher Bright Data tier. Most datasets change daily or weekly; poll at that cadence (`polling_interval_seconds: 86400`).

## Instagram

Monitors public Instagram Business and Creator accounts through Meta's Business Discovery API. You authenticate once with your own Instagram Business account (the viewer), then create one sync per account you want to watch, with its username as `source_path`. You need no relationship with the watched accounts.

Create the connection in Studio under **Connections > Add Connection > Instagram** and complete the OAuth flow. Pick a Facebook Page that has a linked Instagram Business account; without one, Business Discovery does not work. The app needs `instagram_basic`, `pages_show_list` and `business_management`.

| Captured per post | |
| - | - |
| Media | The image or video, downloaded into the bucket |
| `media_type` | `IMAGE`, `VIDEO`, `CAROUSEL_ALBUM` or `REEL` |
| Caption, timestamp, permalink | As posted |
| Like and comment counts | At sync time |

Only public posts are available, with no stories or private accounts. The Graph API allows about 200 calls per hour per viewer account, roughly 5,000 posts per hour at the default page size of 25. Mixpeek halves the page size on server errors (down to 5), honors `Retry-After`, and keeps pages already synced when a later one fails. Tokens last 60 days and refresh automatically within 7 days of expiry; if no sync runs for 60 days, reconnect.

## TikTok

Syncs the videos of the account you authorize through the TikTok Content API, with description, likes, views, shares and comment count on each object. It does not read arbitrary public accounts.

```json title="provider_config" theme={null}
{
  "credentials": {
    "type": "oauth",
    "client_key": "CLIENT_KEY",
    "client_secret": "CLIENT_SECRET",
    "access_token": "ACCESS_TOKEN",
    "refresh_token": "REFRESH_TOKEN",
    "open_id": "OPEN_ID"
  }
}
```

Get these from an approved TikTok Developer app with `user.info.basic` and `video.list` scopes and a Login Kit authorization of the account. Access tokens last 24 hours; Mixpeek renews them with the refresh token. The sync requires `source_path` and the provider ignores it, so pass `/`.

## Email

Each connection gets an inbound address such as `conn_abc123@inbound.mixpeek.com`. Forward or send mail to it, and each email becomes one object.

```json title="provider_config" theme={null}
{"credentials": {"type": "webhook_secret"}, "allowed_senders": ["*@lawfirm.com", "paralegal@partner.com"], "store_raw_eml": true}
```

`inbound_address` and the signing secret are generated for you. `allowed_senders` takes exact addresses or `*@domain` wildcards; empty accepts everyone. Create a sync on the bucket with any `source_path`, such as `inbox`. Mail to a connection with no sync is refused with `400`, and mail from a sender outside the allowlist with `403`.

| Blob | Content |
| - | - |
| `email_body` | Plain-text body, or HTML when there is no plain text |
| `attachment_0`, `attachment_1`, ... | Each attachment, typed by MIME |
| `raw_eml` | The original message, when `store_raw_eml` is `true` (the default) |

Root-level fields: `email_from`, `email_to`, `email_cc`, `email_subject`, `email_date`, `email_message_id`, `email_in_reply_to`, `email_references` and `email_attachment_count`. Filter on them with the `attribute_filter` stage. A second email with the same `Message-ID` is skipped. Email headers and bodies often contain personal data; restrict access to the namespace that holds them.

## What goes wrong

| Symptom | Cause and fix |
| - | - |
| RTSP connection rejected at validation | The URL embeds `user:pass@`, or the scheme is not `rtsp://` or `rtsps://`. HLS streams are not RTSP |
| RTSP run succeeds and the collection processes nothing | No `schema_mapping`, so segments landed on `content`. Map the blob to the property the collection reads |
| RTSP runs overlap | Capture plus about 9 seconds of setup exceeds `polling_interval_seconds` |
| Postgres row appears twice | No `primary_key_columns` on the connection |
| Postgres import refused | A column starts with `_` or collides with a Mixpeek field. Import a renaming view |
| Deleted rows stay searchable | `replication: polling` misses hard deletes. Use `logical` |
| HTTP API sync creates duplicates | `item_id_field` is not unique or not stable across calls |
| Instagram sync finds nothing | The OAuth flow picked a Page with no linked Instagram Business account, or the target is a personal account |
| TikTok sync stops after a day | The refresh token is missing, so the 24-hour access token expired |
| Email answers `400` | No bucket sync is linked to the email connection |

## Related

* [Object storage and syncs](https://docs.mixpeek.com/docs/ingest/object-storage.md): the shared connection and sync flow, filters, schema mapping and reconciliation
* [Buckets and objects](https://docs.mixpeek.com/docs/ingest/buckets.md): object states, duplicates and batches
* [Retrievers](https://docs.mixpeek.com/docs/retrieve/retrievers.md) and [Stages](https://docs.mixpeek.com/docs/retrieve/stages.md): search what you ingested, including `sql_lookup`
* [Create storage connection API](https://docs.mixpeek.com/docs/api-reference/organization-connections/create-storage-connection.md)


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