# Synthetic data

Source: https://docs.autessa.com/docs/features/synthetic-data

> Generate realistic, varied test data from a plain-English description: rows back in one call, or a JSONL or CSV dataset file from a background job.

# Synthetic data

(Preview)

Describe the data you need in plain English. Autessa generates realistic, varied rows that match your columns, with invalid and duplicate rows removed.

## When to use it

- You need test data for an app, a demo, or a load test, without real customer data.
- You need many example conversations or records to test an agent or a classifier.
- You want a dataset file (JSONL or CSV) to train or evaluate a model.

## Quickstart

1. [Get a free API key](https://builder.autessa.com/get-api-key). New accounts get $100 of free credits for your first month, no card needed.
2. Optional: send a description to `POST /clients/synthetic-data/schema/propose` to get suggested columns.
3. Send the description, columns, and a row count to `POST /clients/synthetic-data/generate`.

**curl:**

```bash
curl -X POST https://api.autessa.com/clients/synthetic-data/generate \
  -H "Authorization: $AUTESSA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "description": "Support tickets for an online shoe store. Mix of returns, sizing, and late deliveries.",
    "rowCount": 10,
    "columnDefinitions": [
      {"columnName": "subject", "columnType": "SHORT_TEXT"},
      {"columnName": "body", "columnType": "LONG_TEXT"},
      {"columnName": "priority", "columnType": "SINGLE_SELECT", "allowedValues": ["low", "normal", "urgent"]}
    ]
  }'
```

**Python:**

```python
import os
import requests

res = requests.post(
    "https://api.autessa.com/clients/synthetic-data/generate",
    headers={"Authorization": os.environ["AUTESSA_API_KEY"]},
    json={
        "description": "Support tickets for an online shoe store.",
        "rowCount": 10,
        "columnDefinitions": [
            {"columnName": "subject", "columnType": "SHORT_TEXT"},
            {"columnName": "body", "columnType": "LONG_TEXT"},
        ],
    },
    timeout=300,
)
for row in res.json()["rows"]:
    print(row["subject"])
```

**TypeScript:**

```typescript
const res = await fetch("https://api.autessa.com/clients/synthetic-data/generate", {
  method: "POST",
  headers: { Authorization: process.env.AUTESSA_API_KEY!, "Content-Type": "application/json" },
  body: JSON.stringify({
    description: "Support tickets for an online shoe store.",
    rowCount: 10,
    columnDefinitions: [
      { columnName: "subject", columnType: "SHORT_TEXT" },
      { columnName: "body", columnType: "LONG_TEXT" },
    ],
  }),
});
const { rows, rejectedRowCount } = await res.json();
console.log(rows.length, "rows,", rejectedRowCount, "rejected");
```

**Java:**

```java
var body = """
    {"description": "Support tickets for an online shoe store.", "rowCount": 10,
     "columnDefinitions": [{"columnName": "subject", "columnType": "SHORT_TEXT"},
                           {"columnName": "body", "columnType": "LONG_TEXT"}]}
    """;
var req = java.net.http.HttpRequest.newBuilder(java.net.URI.create("https://api.autessa.com/clients/synthetic-data/generate"))
    .header("Authorization", System.getenv("AUTESSA_API_KEY"))
    .header("Content-Type", "application/json")
    .POST(java.net.http.HttpRequest.BodyPublishers.ofString(body))
    .build();
System.out.println(java.net.http.HttpClient.newHttpClient()
    .send(req, java.net.http.HttpResponse.BodyHandlers.ofString()).body());
```

The response has `rows` (each maps column name to value), `rowCount`, and `rejectedRowCount`. Nothing is stored.

## Larger sets: background jobs

1. `POST /clients/synthetic-data/jobs` with `name`, `description`, `rowCount`, `columnDefinitions`, `targetType: "DATASET_FILE"`, and `fileFormat` (`JSONL` or `CSV`). You get a `jobId`.
2. Poll `GET /clients/synthetic-data/jobs/{jobId}` for `status` and `progressPct`.
3. `GET /clients/synthetic-data/jobs/{jobId}/export` returns a `downloadUrl` for the file.

Set `writeMode: "REVIEW"` to look at staged rows first (`/preview`), then `/approve` or `/discard`.

## How it works

- It writes rows in batches and checks each row against your column types and allowed values.
- It tracks what it has already written, so later batches stay varied instead of repeating.
- It drops invalid and duplicate rows and tries again to reach your count.
- `sampleRowsJson` (a JSON array as a string) gives it example rows to match in style.

**Column types:** `SHORT_TEXT`, `LONG_TEXT`, `INTEGER`, `FLOAT`, `BOOLEAN`, `SINGLE_SELECT`, `MULTI_SELECT`, `DATETIME`. Add a `columnComment` to say what a column holds.

## The synth package

The `synth` package wraps this API in TypeScript (`@autessa/synth`), Python (`autessa-synth`) and Java (`com.autessa:autessa-synth`). It needs only the core package, and reads `AUTESSA_API_KEY`.

- Python: `pip install "autessa-synth @ git+https://github.com/Autessa-Inc/autessa-python#subdirectory=packages/autessa-synth"` (install `autessa-core` the same way first). After release: `pip install autessa-synth`.
- TypeScript: after release, `npm install @autessa/synth`. During the preview, build it from the `autessa-js` repository as its README describes.
- Java: the `com.autessa:autessa-synth` artifact, plus `autessa-spring-boot-starter` for Spring Boot. During the preview, build `autessa-java` from source first.

### Propose a schema, then generate rows

**TypeScript:**

```typescript
import { Synth } from "@autessa/synth";

const synth = new Synth();
const { schema } = await synth.proposeSchema({ description: "support tickets for a bike shop" });
const { rows } = await synth.generate({
  description: "support tickets for a bike shop",
  columns: schema.columnDefinitions,
  rowCount: 20,
});
console.log(rows[0]);
```

**Python:**

```python
from autessa.synth import Synth

synth = Synth()
proposal = synth.propose_schema("support tickets for a bike shop")
rows = synth.generate(description="support tickets for a bike shop",
                      columns=proposal.schema_.column_definitions, row_count=20).rows
print(rows[0])
```

**Java:**

```java
import com.autessa.synth.Synth;

Synth synth = Synth.fromEnv();
List<Map<String, Object>> rows = synth.generate("Support tickets for a bike shop", 20);
rows.forEach(System.out::println);
```

`synth.proposeSchema(description)` returns suggested columns.

### Many rows: jobs, review and export

A job runs in the background and writes a dataset file (JSONL or CSV). With an API key, jobs always write files. With `writeMode: "REVIEW"`, it stops at `AWAITING_REVIEW` so you can look at a batch, drop rows, and approve.

**TypeScript:**

```typescript
const jobId = await synth.createJob({
  name: "tickets", description: "support tickets", rowCount: 5000,
  fileFormat: "JSONL", writeMode: "REVIEW",
});
await synth.waitForJob(jobId);                     // stops at AWAITING_REVIEW, or when finished
const { rows, batchId } = await synth.preview(jobId);
await synth.excludeRows(jobId, batchId!, [3, 7]);
await synth.approve(jobId);
await synth.waitForJob(jobId);
const { downloadUrl } = await synth.export(jobId);
```

**Python:**

```python
job_id = synth.create_job(row_count=5000, name="tickets", description="support tickets",
                          file_format="JSONL", write_mode="REVIEW")
synth.wait_for_job(job_id)                         # stops at AWAITING_REVIEW, or when finished
batch = synth.preview(job_id)
synth.approve(job_id)
synth.wait_for_job(job_id)
print(synth.export(job_id).download_url)
```

**Java:**

```java
String jobId = synth.createJob(new CreateSyntheticDataJobRequest()
    .description("Member intake calls for a health plan").rowCount(2000).fileFormat("CSV"));
SyntheticDataJobSummaryDto job = synth.waitForJob(jobId);   // stops at AWAITING_REVIEW, or when finished
if ("AWAITING_REVIEW".equals(job.getStatus())) {
  synth.preview(jobId);
  synth.approve(jobId);
}
System.out.println(synth.export(jobId).downloadUrl());
```

| Call | What it does |
| --- | --- |
| `proposeSchema` | Suggested columns for a description. |
| `generate` | A small set of rows right away. |
| `createJob`, `getJob`, `listJobs`, `waitForJob` | Many rows in the background. |
| `preview`, `approve`, `discard`, `cancel` | Review a staged batch, then keep it, throw it away, or stop the job. |
| `append`, `excludeRows`, `regenerateBatch` | Add rows, drop rows, or redo a batch before approving. |
| `export` | A download link for the job's file. |

Python uses snake_case (`propose_schema`, `wait_for_job`, ...) and has `AsyncSynth`.

### Use the rows in evals and tests

Two helpers turn rows into plain data, so the synth package doesn't depend on any other Autessa package:

- `toEvalCases(rows, mapping)` makes one grading case per row, in the shape [Evaluations](/docs/features/evaluations.md) `grade` takes.
- `toSeed(rows)` makes rows for a local test's `seed:` block, or for `table(x).seed(...)` in the [CDK's offline tests](/docs/cdk/agents.md#test-it-offline).

**TypeScript:**

```typescript
import { toEvalCases, toSeed } from "@autessa/synth";

const cases = toEvalCases(rows, { user: "question", expectedOutcome: "expected", agentInstructions: "You help with orders." });
const seed = toSeed(rows, ["orderId", "status"]);
```

**Python:**

```python
from autessa.synth import to_eval_cases, to_seed

cases = to_eval_cases(rows, {"user": "question", "expected_outcome": "expected"},
                      agent_instructions="You help with orders.")
seed = to_seed(rows, table="Orders")
# each case goes straight to Evals().grade(**case)
```

**Java:**

```java
List<EvalGradeRequest> cases = Synth.toEvalCases(rows, EvalCaseMapping.builder()
    .agentInstructions("You help with orders.")
    .userMessage("question")
    .expectedOutcome("expected")
    .build());
List<Map<String, Object>> seed = Synth.toSeed(rows);
```

## Limits

- `/generate` is for small sets. Use a job for more rows.
- Each job has a maximum row count. The API tells you if a request is over it.
- With an API key, jobs write files. To fill an AutessaDB table, use the Builder.
- Usage is billed to your company. See [Billing](/docs/guide/company/billing.md).

## API reference

[Synthetic Data API](/docs/reference/synthetic-data.md)

## Benchmarks

None for synthetic data. See [Benchmarks](/docs/benchmarks.md) for what we publish.

## Related

- [Evaluations](/docs/features/evaluations.md)
- [AutessaDB tables](/docs/guide/autessadb/tables.md)
- [Start here](/docs/start.md)

