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

> ## Agent Instructions
> To set up Hue in an application, fetch https://docs.hue.run/guides/agent-setup.md and follow it.
> Hue's project-data MCP server is https://mcp.hue.run/mcp. https://docs.hue.run/mcp only searches these docs and cannot read a Hue project.
> Never ask the user to paste a Hue API key into chat; they store it as HUE_API_KEY themselves.
> Install the exact SDK versions pinned on the page you're following, or on https://docs.hue.run/quickstart.md. Run the latest CLI without a project install as `npx -y @hue-run/sdk@latest`. In a project with `@hue-run/sdk` installed, use `npx hue`. Pin an exact version for reproducible CI runs.
> Use Hue product terms: eval set, case, evaluator, run and scoring run. Older APIs may say dataset, scorer or experiment; prefer the current SDK methods. See https://docs.hue.run/concepts.md.

# Using Postgres

> Connect your agent to the hosted Postgres database for a World instance.

Each World instance gets its own writable Postgres database, initialized from the saved rows. Hue hosts it; you don't need to run Postgres locally.

## Describe your tables

Select **Postgres** when you [generate a World](https://docs.hue.run/worlds/create-with-mcp.md#generate-in-hue), or include `postgres` in `create_world` over MCP. Describe the tables, columns, types, defaults, relationships, and starting rows you need. Hue fills in details you leave open. For example:

```text Prompt wrap theme={null}
Create a World with Postgres for a fictional parts warehouse. Add one table called stock_levels with columns sku (text primary key), label (text), and quantity (integer, default 0). Seed one row: sku BOLT-01, label Hex bolt, quantity 12.
```

To add Postgres to a World you already have, send the same table description and the World link to your coding agent. Ask it to use `edit_world` and keep the other apps unchanged. Check **Postgres → Starting rows** on the new version. This preview does not start a database.

Use up to 12 tables with 24 columns each and up to 20,000 starting rows or 10 MiB, whichever you reach first. Hue supports text, integer, bigint, numeric, boolean, date, timestamptz, UUID, and JSONB. Use a single-column primary key per table and foreign keys to primary keys. Defaults can be literals, the current timestamp, or a generated UUID. Hue runs PostgreSQL 17 without extensions. Describe the schema rather than supplying SQL or a dump.

## Connect your agent

1. Open a World with Postgres and choose **Start instance**.
2. Select **Postgres → Connect → Copy URL**. If it's still preparing, choose **Prepare** to check again.
3. Pass that URL to your agent's Postgres client as a secret for this run. Don't put it in prompts or logs.

Set up TLS once per environment. Download the [server CA bundle](https://truststore.pki.rds.amazonaws.com/us-east-1/us-east-1-bundle.pem) and set `PGSSLROOTCERT` to its path. Keep hostname and certificate verification on. Only the URL changes each run.

To read and update the warehouse fixture, install [`pg`](https://node-postgres.com/) or `psycopg[binary]`. Set `WORLD_DATABASE_URL` for this process only, or pass the URL directly to the client. Don't change the parent process environment for concurrent instances.

```javascript Node.js theme={null}
import { readFileSync } from "node:fs";
import pg from "pg";

const target = new URL(process.env.WORLD_DATABASE_URL);
// node-postgres URL parameters can override the ssl options object.
target.search = "";
const client = new pg.Client({
  connectionString: target.toString(),
  ssl: {
    ca: readFileSync(process.env.PGSSLROOTCERT, "utf8"),
    rejectUnauthorized: true,
  },
  connectionTimeoutMillis: 5000,
});

try {
  await client.connect();
  const sku = ["BOLT-01"];
  const before = await client.query("SELECT quantity FROM stock_levels WHERE sku = $1", sku);
  const after = await client.query(
    "UPDATE stock_levels SET quantity = quantity - 1 WHERE sku = $1 RETURNING quantity",
    sku,
  );
  console.log(before.rows[0].quantity, after.rows[0].quantity); // 12 11 on a fresh instance
} finally {
  await client.end();
}
```

```python Python theme={null}
import os
import psycopg

with psycopg.connect(os.environ["WORLD_DATABASE_URL"], connect_timeout=5) as connection:
    sku = ("BOLT-01",)
    before = connection.execute(
        "SELECT quantity FROM stock_levels WHERE sku = %s", sku
    ).fetchone()[0]
    after = connection.execute(
        "UPDATE stock_levels SET quantity = quantity - 1 WHERE sku = %s RETURNING quantity", sku
    ).fetchone()[0]
    print(before, after)  # 12 11 on a fresh instance
```

Stop the instance when you finish. At stop or expiry, Hue removes the database. Start a fresh instance and use its URL to see `12 11` again. The saved seed stays unchanged.

## Connect a harness through the API

Send requests to `https://app.hue.run` with `Content-Type: application/json` and `Authorization: Bearer <project key>`. Use the same server-side [Read and write key](https://docs.hue.run/quickstart.md#project-keys) for start, reveal, and finish. To select a project other than the key's default, send the same `X-Hue-Project: <project-id>` on every request.

1. `POST /api/v1/environment-runs` with `X-Hue-Native-Connections: 1` and `{"environmentVersionId":"<world-version-id>","idempotencyKey":"<start-key>"}`. Use the version ID, not the World ID. Reuse the key if retrying the same start.
2. From the start response, take `id` and find the entry in `nativeApps` with `providerId` equal to `postgres`. Send that entry's `appKey` in the JSON body of `POST /api/v1/environment-runs/{id}/native-connection`. Poll while `state` is `preparing`. When it's `ready`, pass `url` to that run's client. If setup fails, finish the instance rather than connecting to a fallback database. MCP can start a World but does not reveal its SQL credentials.
3. Collect any SQL evidence, then `POST /api/v1/environment-runs/{id}/finish` in a `finally` block. Send `{"status":"completed","idempotencyKey":"<finish-key>"}` on success, or `"status":"abandoned"` if setup or the run fails or you cancel it.

Each instance allows four harness connections. **Live rows** is available only for standalone instances.


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