# Supabase Sync

> Keep your Virlo research as live tables in your own Supabase database: your agents' videos, creators and runs, updated after every run. Connect in three clicks, no keys or SQL.

Source: https://dev.virlo.ai/docs/supabase
Markdown: https://dev.virlo.ai/docs/supabase.md
Section: How the API works

## About the Virlo API (applies to every page)

- Base URL: `https://api.virlo.ai/v1`. Every request needs the header `Authorization: Bearer YOUR_API_KEY` (keys start with `virlo_tkn_`).
- Responses are JSON inside a `data` field, except the `/v1/webhooks` endpoints, which return the object or array directly. Field names are snake_case.
- Prices are in US dollars from a prepaid balance. 1 credit = $0.01. The `X-Cost` response header on each successful response is the exact charge. Errors are free.
- Slow jobs return an ID. Check its status every 15 seconds (or whatever `retry_after_seconds` says) until `finalized` is `true`.
- All docs pages: https://dev.virlo.ai/llms.txt. Every page in one file: https://dev.virlo.ai/llms-full.txt. MCP server for AI assistants: https://dev.virlo.ai/api/mcp/mcp.

---

Supabase Sync keeps your Virlo research in your own Supabase database. Your agents' videos, creators and runs land as Postgres tables and stay up to date after every run, ready for your own apps, dashboards and AI agents.

**At a glance**

- **What it does:** Writes your agents' data into tables in a Supabase project you own, and keeps it current.
- **You do:** Connect Supabase, pick a project, choose what syncs.
- **You get:** Five `virlo_*` tables: agents, videos, daily views history, creators and runs.
- **Cost:** Included in every paid Virlo plan. No credits are used.
- **How fresh:** Within 30 minutes of each agent run finishing, or right away with Sync now.

---

## What you get

An export gives you a file. Supabase Sync gives you tables that keep themselves current:

- **Numbers refresh in place.** A video's views, likes and shares update on the same row each sync.
- **History builds up.** `virlo_video_stats` adds a row per video per day, so you can chart how a video grew.
- **Everything joins.** Videos link to their creators and to the agents that found them, and you can join all of it with your own tables.
- **It's your database.** Query it with SQL, supabase-js, Supabase's REST API, or any Postgres tool.

---

## Set it up

1. In Virlo, open **Automations > Apps** and choose **Supabase** under **Your data**. Or start from one agent: open its **Export** dialog and press **Connect** on **Keep it in Supabase**.
2. Supabase asks you to approve Virlo. Approve it for the organization that holds your project.
3. Back in Virlo, pick the project and what syncs, then press **Create tables and sync**.

Virlo creates its tables in that project and starts the first sync. Open your project's Table Editor to see rows arrive as each agent finishes. If you started from an agent's Export, that agent is written first and Virlo takes you back to it.

> **Note:** Pick a project whose database you are happy for Virlo to add tables to. Virlo only creates and writes its own `virlo_*` tables and never reads or changes any other table.

---

## What syncs

You choose one of two options when you connect, and you can switch any time on the Supabase card:

| Option | What it sends | When |
| - | - | - |
| **Everything** | Every agent in the workspace you connected from. New agents are included automatically. | Within 30 minutes of each run finishing. |
| **Agents I choose** | Only the agents you add. Add one from its Export dialog (**Keep it in Supabase > Add**). Automations whose **Where** is Supabase add theirs too. | Within 30 minutes of each run finishing, and each time such an automation runs. |

Connecting from an agent's Export starts with **Agents I choose** and just that agent selected, so one agent stays one agent. Switch to Everything at any time.

**Sync now** on the card sends everything it covers straight away, even if nothing new ran.

---

## The tables

All five tables are in the `public` schema. Each one also has `first_synced_at` and `synced_at`, and every column has a comment you can read in the Table Editor.

### virlo_agents

One row per agent. Key: `agent_id`.

| Column | Type | Description |
| - | - | - |
| `agent_id` | uuid | The agent id in Virlo. |
| `name` | text | Agent name. |
| `kind` | text | `recurring` or `one-time`. |
| `keywords` | text[] | Keywords the agent searches. |
| `platforms` | text[] | Platforms the agent covers. |
| `intent` | text | What the agent researches, from its brief. |
| `video_count` | integer | Videos the agent has collected. |
| `last_run_at` | timestamptz | When its latest finished run started. |
| `virlo_url` | text | Opens the agent in Virlo. |

### virlo_videos

One row per video. Key: `video_id`. Its numbers update on every sync.

| Column | Type | Description |
| - | - | - |
| `video_id` | text | The video id in Virlo. |
| `platform` | text | `tiktok`, `youtube` or `instagram`. |
| `url` | text | Link to the video. |
| `platform_video_id` | text | The platform's own id. |
| `published_at` | timestamptz | When it was posted. |
| `duration_seconds` | numeric | Length in seconds. |
| `views`, `likes`, `comments`, `shares`, `saves` | bigint | Numbers at the latest sync. |
| `caption` | text | The post caption. |
| `hashtags` | text[] | Hashtags in the caption. |
| `is_outlier` | boolean | Beat the creator's usual views. |
| `outlier_ratio` | numeric | Views divided by the creator's typical views. |
| `virality_score` | numeric | Virlo virality score. |
| `thumbnail_url` | text | Cover image. |
| `transcript` | text | What is said in the video, when available. |
| `sound_id` | text | The sound used, when known. |
| `region` | text | Region the video was found in. |
| `creator_id`, `creator_username`, `creator_followers` | text, text, bigint | The creator. `creator_id` joins to `virlo_creators`. |
| `hook_text` | text | The opening line or on-screen hook. |
| `content_format` | text | Format, for example talking head or tutorial. |
| `primary_topic` | text | Main topic. |
| `intelligence` | jsonb | Every [Data Intelligence](https://dev.virlo.ai/docs/intelligence) field for the video. |
| `agent_ids` | uuid[] | The agents that collected it. Joins to `virlo_agents`. |
| `first_collected_at` | timestamptz | When an agent first collected it. |

### virlo_video_stats

One row per video per day it was synced. Key: `video_id, day`. Columns: `video_id`, `day` (date, UTC), `views`, `likes`, `comments`, `shares`.

### virlo_creators

One row per creator. Key: `creator_id`. Columns: `platform`, `username`, `display_name`, `profile_url`, `followers`, `verified`, `country`, `is_outlier_creator`, `avg_views`, `median_views`, `outlier_ratio`, `top_video_views`, `posts_per_week`, `content_angle`, `agent_ids`.

### virlo_agent_runs

One row per run. Key: `run_id`. Columns: `agent_id`, `run_number`, `status`, `started_at`, `completed_at`, `new_videos`, `outliers_found`, `total_videos_after`, `total_views_after`.

> **Note:** Virlo overwrites its rows on each sync, so keep your own notes and columns in a separate table that references `video_id` or `creator_id`. New columns may be added over time. Existing columns are never renamed or removed.

---

## Example queries

**This week's top videos across all your agents**

```sql
select caption, creator_username, views, outlier_ratio, url
from virlo_videos
where published_at > now() - interval '7 days'
order by views desc
limit 20;
```

**Hooks that over-perform, by format**

```sql
select content_format, count(*) as videos, round(avg(outlier_ratio), 2) as avg_outlier
from virlo_videos
where outlier_ratio is not null
group by content_format
order by avg_outlier desc;
```

**One video's growth, day by day**

```sql
select day, views
from virlo_video_stats
where video_id = '<video_id>'
order by day;
```

**Videos from one agent**

```sql
select v.caption, v.views, v.url
from virlo_videos v
join virlo_agents a on a.agent_id = any (v.agent_ids)
where a.name = 'My agent'
order by v.views desc;
```

**From your app with supabase-js** (after you add a read policy, see below)

**JavaScript:**

```js
const { data } = await supabase
  .from('virlo_videos')
  .select('caption, views, url')
  .order('views', { ascending: false })
  .limit(10)
```

---

## Access and security

- **Row level security is on** for every `virlo_*` table, with no policies. Your project's public (anon) key can read nothing until you add a policy, for example `create policy "read" on virlo_videos for select to authenticated using (true);`.
- **What Virlo can do.** You approve Virlo through Supabase's own consent screen. Virlo uses that access only to list your projects and to create and write its own tables in the project you pick.
- **What Virlo stores.** The access token Supabase issues, encrypted, and nothing else from your account. Virlo never asks for your database password or service key.
- **Revoking.** Remove Virlo from your organization's settings in Supabase at any time. Syncing stops at once and the Supabase card in Virlo asks you to reconnect.

---

## Disconnecting

Choose **Disconnect** on the Supabase card. Virlo deletes its access token and stops syncing. Your tables and their rows stay in your project: they are yours. Delete them whenever you like.

To sync again later, connect the same project. Virlo picks up where it left off and your automations keep working.

---

## Questions

**Which plans include it?** Every paid Virlo plan. On a trial, the card shows the sync waiting and starts once your plan is active.

**Does it use credits?** No. It sends data your agents already collected.

**Which workspace syncs?** The one you connected from, and the connection only shows in that workspace. Connect again from another workspace to sync that one too, even into the same project.

**Can I sync to more than one project?** Yes. Connect Supabase again and pick another project.

**Something failed.** The Supabase card says what went wrong in plain words and when your tables last updated. Most failures, such as a paused project or a revoked approval, are fixed by restoring the project or reconnecting.

---

More in How the API works:

- [How results load](https://dev.virlo.ai/docs/async-data.md)
- [Pagination](https://dev.virlo.ai/docs/pagination.md)
- [Rate limits](https://dev.virlo.ai/docs/rate-limits.md)
- [Webhooks](https://dev.virlo.ai/docs/webhooks.md)
- [Errors](https://dev.virlo.ai/docs/errors.md)
- [Workflow recipes](https://dev.virlo.ai/docs/recipes.md)
- [API playground](https://dev.virlo.ai/docs/playground.md)
