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

# Typegen manifest

> Fetch variable metadata for type generation tools and IDE plugins.

## GET /v1/typegen/manifest

Returns the metadata for all variables in a stage in a format suitable for type generation tools, IDE plugins, and codegen scripts. This endpoint returns the same metadata as `/v1/env/list` but structured for tooling consumption.

<Note>
  This endpoint is for tooling, not for reading variable values. Use
  `/v1/env/evaluate` or the SDK to fetch values at runtime.
</Note>

### Request

```bash theme={null}
curl "https://api.barekey.dev/v1/typegen/manifest?orgSlug=acme-42&projectSlug=backend-api-1234&stageSlug=production" \
  -H "Authorization: Bearer bk_at_..."
```

**Query parameters:**

| Parameter     | Type     | Required | Description       |
| ------------- | -------- | -------- | ----------------- |
| `orgSlug`     | `string` | Yes      | Organization slug |
| `projectSlug` | `string` | Yes      | Project slug      |
| `stageSlug`   | `string` | Yes      | Stage name        |

### Response

```json theme={null}
{
  "manifestVersion": 1,
  "variables": [
    {
      "name": "DATABASE_URL",
      "kind": "secret",
      "declaredType": "string"
    },
    {
      "name": "MAX_CONNECTIONS",
      "kind": "secret",
      "declaredType": "int64"
    },
    {
      "name": "FEATURE_FLAGS",
      "kind": "secret",
      "declaredType": "json"
    },
    {
      "name": "CHECKOUT_FLOW",
      "kind": "ab_roll",
      "declaredType": "string",
      "chance": 0.2
    }
  ],
  "requestId": "req_01hx..."
}
```

**Response fields:**

| Field             | Type     | Description                                           |
| ----------------- | -------- | ----------------------------------------------------- |
| `manifestVersion` | `number` | Schema version of the manifest format. Currently `1`. |
| `variables`       | `array`  | Variable metadata array                               |
| `requestId`       | `string` | Request trace ID                                      |

**Each variable:**

| Field          | Type                      | Always present | Description           |
| -------------- | ------------------------- | -------------- | --------------------- |
| `name`         | `string`                  | Yes            | Variable name         |
| `kind`         | `"secret"` \| `"ab_roll"` | Yes            | Variable kind         |
| `declaredType` | `string`                  | No             | Declared type, if set |
| `chance`       | `number`                  | `ab_roll` only | A/B chance value      |

### Use cases

**Type-safe SDK wrapper generation**

A codegen script can use this manifest to generate a typed wrapper around the SDK:

```typescript theme={null}
// Generated by barekey-typegen
import { BarekeyClient } from "@barekey/sdk/server";

export async function getEnv(client: BarekeyClient) {
  return {
    DATABASE_URL: () => client.get("DATABASE_URL"),
    MAX_CONNECTIONS: () => client.get("MAX_CONNECTIONS"),
    FEATURE_FLAGS: () => client.get("FEATURE_FLAGS"),
    CHECKOUT_FLOW: (opts?: { seed: string; key: string }) =>
      client.get("CHECKOUT_FLOW", opts),
  };
}
```

**IDE plugin integration**

IDE plugins can fetch the manifest and provide autocompletion for variable names and return types when calling `barekey.get(...)`.

### Error codes

| Code                | HTTP | When                                                             |
| ------------------- | ---- | ---------------------------------------------------------------- |
| `UNAUTHORIZED`      | 401  | Invalid or expired token                                         |
| `INVALID_REQUEST`   | 400  | Missing `orgSlug`, `projectSlug`, or `stageSlug` query parameter |
| `INVALID_ORG_SCOPE` | 403  | Token org doesn't have access to this project                    |
