# Random records API

Sample coherent synthetic records conforming to any compiled record schema in your dictionary.

> [!NOTE]
> The project ID in the path must match the project permanently bound to your Bearer API key. The unscoped route `GET /v1/random/{recordType}` remains available for backward compatibility, but new integrations should specify the project ID explicitly.

## Endpoint

```text
GET /v1/projects/{project_id}/random/{recordType}
```

CLI equivalent: `simhealth sample {recordType} --count 1 --seed 1842`

## Request parameters

| Parameter | Placement | Type | Required | Default | Description |
| --- | --- | --- | --- | --- | --- |
| `project_id` | path | string | required | - | Unique identifier of the dictionary project workspace. |
| `recordType` | path | string | required | - | Record definition name (e.g. `person`, `patient`, `encounter`). |
| `count` | query | integer | optional | `1` | Number of records to generate. Up to 10,000 for JSON, 10,000,000 for Avro. |
| `seed` | query | integer | optional | random | 64-bit unsigned integer seed for deterministic generation. |
| `fields` | query | string | optional | all | Comma-separated list of field names to project in the output. |

## Headers and content negotiation

| Header | Format / Semantics |
| --- | --- |
| `Authorization: Bearer <KEY>` | **Required**. A valid project-bound API key or signed-in Firebase ID token. |
| `Accept: application/json` | Default. Returns buffered JSON payload (up to 10,000 records). |
| `Accept: application/avro-binary` | Streaming binary Avro Object Container File (OCF), up to 10,000,000 records. |
| `Accept: application/x-ndjson` | Line-by-line Newline-Delimited JSON stream. |
| `x-customer-id` | *Optional* ledger tracking identifier. Must be 1–128 ASCII letters, digits, `_`, or `-`. |

> [!TIP]
> Use `Accept: application/avro-binary` for bulk migrations or machine learning datasets. Avro streaming uses zero server buffering and is up to 12x faster to decode than JSON.

## Code examples

```tabs
=== cURL
```bash
curl -s -H "Authorization: Bearer $SIMHEALTH_API_KEY" \
  -H "Accept: application/json" \
  "https://api.preprod.simhealth.interoperabilitypro.com/v1/projects/default/random/person?count=1&seed=1842"
```
=== Python
```python
import requests

url = "https://api.preprod.simhealth.interoperabilitypro.com/v1/projects/default/random/person"
headers = {"Authorization": "Bearer $SIMHEALTH_API_KEY"}
params = {"count": 1, "seed": 1842}

response = requests.get(url, headers=headers, params=params)
data = response.json()
print(data["records"][0])
```
=== TypeScript
```typescript
const response = await fetch(
  "https://api.preprod.simhealth.interoperabilitypro.com/v1/projects/default/random/person?count=1&seed=1842",
  {
    headers: { Authorization: "Bearer " + process.env.SIMHEALTH_API_KEY },
  }
);
const data = await response.json();
console.log(data.records[0]);
```
=== SimHealth CLI
```bash
simhealth sample person --count 1 --seed 1842 --format json
```
```

## Response schema

### 200 OK (application/json)

```json
{
  "recordType": "person",
  "count": 1,
  "seed": 1842,
  "records": [
    {
      "person_id": "P-981742",
      "first_name": "Maria",
      "last_name": "Santos",
      "gender": "female",
      "birth_date": "1984-06-12",
      "mrn": "MRN-004928"
    }
  ]
}
```

### 400 Bad Request

```json
{
  "error": "invalid customer id",
  "message": "invalid customer id"
}
```

### 403 Forbidden

```json
{
  "error": "project mismatch",
  "message": "API key is bound to project 'default', cannot access project 'finance-qa'"
}
```
