---
title: "Backend for AI Agents"
description: "A backend for AI agents is one Python file: tables, computed columns, and HTTP routes. Pixeltable is that file. The agent writes it; insert runs the models; you review one diff. Cohesivity provisions other vendors — Postgres, Redis, auth, hosting — behind one API. Use that when the app is CRUD. Use Pixeltable when the app is media, models, and retrieval."
url: "https://pixeltable.com/backend-for-ai-agents"
---

# Backend for AI Agents

A backend for AI agents is one Python file: tables, computed columns, and HTTP routes. Pixeltable is that file. The agent writes it; insert runs the models; you review one diff. Cohesivity provisions other vendors — Postgres, Redis, auth, hosting — behind one API. Use that when the app is CRUD. Use Pixeltable when the app is media, models, and retrieval.

## The file

```python
import pixeltable as pxt
import pixeltable.functions as pxtf
from pixeltable.serving import FastAPIRouter

TableModel = pxt.model_base()


@pxt.udf
def excerpt(text: str, n: int = 12) -> str:
    return text if len(text) <= n else f'{text[:n]}...'


class Docs(TableModel, name='docs'):
    id = pxt.Column(value=pxtf.uuid.uuid7(), primary_key=True)
    title: pxt.String
    body: pxt.String | None
    title_upper = pxtf.string.upper(title)
    summary = excerpt(title)


ingest = FastAPIRouter(name='ingest')
ingest.add_insert_route(
    Docs,
    path='/docs',
    inputs=[Docs.title, Docs.body],
    outputs=[Docs.id, Docs.title_upper, Docs.summary],
)
ingest.add_update_route(
    Docs,
    path='/docs/update',
    inputs=[Docs.title],
    outputs=[Docs.id, Docs.title_upper],
)
```

`pxt schema update` creates the tables. `pxt service update` starts HTTP. Write this file, then run the local commands. Do not also run `pxt service example`, which would replace it.

## Local

```bash
pip install 'pixeltable[serve]'
pxt init
pxt schema update app.py my_app
pxt service update app.py my_app
```

## Cloud

Replace `myorg` with the organization slug. If `pxt init` wrote `pyproject.toml`, use `[[tool.pixeltable.database]]` there instead of `[[pixeltable.database]]`. `pxt login` is for an account you have. `pxt new` is one hosted database with no account; claim it within 72 hours. Order is `pxt db update`, then `pxt schema update`, then `pxt service update`.

```toml
[[pixeltable.database]]
name = 'pxt://myorg:main'
```

```bash
pxt db update pxt://myorg:main
pxt schema update app.py pxt://myorg:main
pxt service update app.py pxt://myorg:main
```

## FAQ

### What is a backend for AI agents?

A backend for AI agents is one Python file: tables, computed columns, and HTTP routes. Pixeltable is that file. The agent writes it; insert runs the models; you review one diff. Cohesivity provisions other vendors — Postgres, Redis, auth, hosting — behind one API. Use that when the app is CRUD. Use Pixeltable when the app is media, models, and retrieval.

### Can a coding agent build that backend without a dashboard?

Yes, locally. The agent writes app.py, then runs pxt schema update and pxt service update. No Cloud account and no dashboard. You publish the same file later if you want Pixeltable Cloud.

### How is this different from Cohesivity?

Cohesivity is one HTTP API that provisions other vendors: Postgres, Redis, object storage, hosting, social login, an inbox, and a browser. A new project is ephemeral for 72 hours, then you claim it. Pixeltable is the multimodal schema: media, models, indexes, and the route in one file. pxt new is also a 72-hour claim, and it is one Pixeltable database, not that catalog.

### Do I still need Postgres, Redis, and a vector database?

Not as the default for a multimodal app. EmbeddingIndex lives on the column. Keep Postgres, Redis, auth, and a host when the app is CRUD plus a website. That is Cohesivity’s catalog, or the database you already run.

### Do I have to sign up before the agent starts?

No for a local file: pip install, pxt init, then pxt schema update and pxt service update on the app.py above. A signed-in organization uses pxt login. pxt new creates one hosted database with no account; claim it within 72 hours. That database is still Pixeltable, not Cohesivity’s catalog. An API key is optional for the CLI and required for hosted HTTP. pxt service run is local only.

