---
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://www.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. An agent's shell has no TTY to confirm in, so each update carries `-f`.

## Local

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

## Cloud

Replace `myorg` with the organization slug. `pxt db update --add-config-entry` writes the hosted entry, including when the project configuration is in `pyproject.toml`. `pxt login` is for an account you have. `pxt new` is one hosted database with no account; claim it within 48 hours. Order is `pxt db update`, then `pxt schema update`, then `pxt service update`; a schema applied before the database fails with `404: UDF not found`.

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

```bash
pxt db update pxt://myorg:main --add-config-entry -f
pxt schema update app.py pxt://myorg:main -f
pxt service update app.py pxt://myorg:main -f
```

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

