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

> ## Agent Instructions
> Use Stable documentation by default. Honor an explicit Beta request or a URL under /docs/beta/. If the requested version conflicts with the installed CLI package or API origin, clarify the target before writing integration code.
> Pages under /docs/beta/ document Beta; other product pages document Stable. Keep the CLI package, commands, API origin, and credentials within the selected version. State the documentation version in your answer.
> For MCP search, always pass version: Stable or version: Beta. Unfiltered search mixes both versions. For filesystem reads, keep Beta queries under /beta/ and exclude /beta/ from Stable queries; discover paths before reading them.
> The public docs base is https://photon.codes/docs. Convert MCP page paths to public URLs under that base, preserving /beta/ when present. Read https://photon.codes/docs/skill.md for version selection and https://photon.codes/docs/llms.txt for the version indexes.

# ADS-0002: Top-Level JSON Response Structure

> Flat top-level JSON objects for Photon public HTTP API responses, prohibiting bare arrays, single-resource wrapper envelopes, and split resource-and-secret creation wrappers.

* **Status**: Approved
* **Updated**: 2026-11-22

Consistent top-level JSON response shapes let callers, generated SDKs, and agents read resource fields directly without unwrapping per-endpoint envelopes or switching parsing logic between creation and retrieval responses. This standard is part of Photon API Design Standards and uses the keywords **MUST**, **MUST NOT**, **SHOULD**, and **MAY** as described in RFC 2119.

## Normative Rules

### 1. Top-level JSON responses MUST be JSON objects

Every `2xx` JSON response (`application/json` or `application/*+json`) **MUST** have a JSON object at the root.

* Responses **MUST NOT** return a bare JSON array (`[...]`) at the top level, because top-level arrays cannot be extended with pagination cursors or collection metadata without a breaking change.
* Responses **MUST NOT** return a top-level JSON primitive (`"ok"`, `true`, `42`, or `null`).
* `204 No Content` responses and non-JSON media types (such as binary downloads or plain text) are unaffected by this rule.

### 2. Single-resource responses MUST be returned directly at the top level

`GET`, `POST`, `PATCH`, `PUT`, and `DELETE` responses returning a single resource **MUST** place the resource's fields directly at the root object (`{ "id": "...", ... }`).

* Responses **MUST NOT** wrap a single resource in a single-key resource envelope (such as `{ "apiKey": { ... } }`, `{ "project": { ... } }`, or `{ "organization": { ... } }`).
* Responses **MUST NOT** wrap a single resource under a generic envelope key (`data`, `result`, or `payload`), whether alone or paired with metadata keys such as `meta`.

### 3. Creation responses with one-time secrets MUST remain flat

When a `POST` endpoint creates a resource and returns a one-time sensitive value (such as `secret`, `signingSecret`, `clientSecret`, `token`, or `accessToken`), the response **MUST** return the resource directly at the top level with the one-time value as a sibling top-level property.

* Subsequent `GET`, `PATCH`, and `DELETE` responses for the same resource omit the one-time secret while keeping every other top-level resource field in the exact same position.
* Creation responses **MUST NOT** split the resource and one-time secret into a two-key wrapper envelope such as `{ "apiKey": { ... }, "secret": "..." }` or `{ "destination": { ... }, "signingSecret": "..." }`.

### 4. Allowed multi-field and non-resource top-level objects

Top-level JSON objects are **NOT** restricted to single resources. The following shapes are explicitly allowed:

* **Collections**: Top-level objects wrapping a list array, with or without pagination fields (for example `{ "items": [ ... ], "nextCursor": null }`).
* **Free-form key-value maps**: Open dictionary objects with dynamic keys (for example label or attribute maps).
* **Scalar utility responses**: Objects returning scalar summaries, counts, or links (for example `{ "count": 42 }` or `{ "url": "https://example.com/..." }`).
* **Multi-entity composite responses**: Objects returning two or more peer entities (for example `{ "operation": { ... }, "resource": { ... } }`).
* **Nullable sub-objects with or without sibling metadata**: Objects whose sub-object property may be `null` (for example `{ "subscription": null, "timeZone": "UTC" }`).

## Examples

### Single-resource responses (`GET`, `PATCH`)

**Good** — resource fields returned directly at the top level (`GET /v1/projects/{projectId}/api-keys/{apiKeyId}`):

```json theme={null}
{
  "id": "key_01h455vb4pex5vsknk084sn02r",
  "projectId": "prj_01h455vb4pex5vsknk084sn02q",
  "organizationId": "org_01h455vb4pex5vsknk084sn02s",
  "name": "Production server key",
  "createdAt": "2026-11-22T10:00:00Z"
}
```

**Bad** — wrapped in a single-key resource envelope:

```json theme={null}
{
  "apiKey": {
    "id": "key_01h455vb4pex5vsknk084sn02r",
    "projectId": "prj_01h455vb4pex5vsknk084sn02q",
    "organizationId": "org_01h455vb4pex5vsknk084sn02s",
    "name": "Production server key",
    "createdAt": "2026-11-22T10:00:00Z"
  }
}
```

**Bad** — wrapped in a generic `data` envelope (alone or alongside `meta`):

```json theme={null}
{
  "data": {
    "id": "prj_01h455vb4pex5vsknk084sn02q",
    "organizationId": "org_01h455vb4pex5vsknk084sn02s",
    "name": "Acme Billing"
  },
  "meta": {
    "requestId": "req_01h455vb4pex5vsknk084sn02t"
  }
}
```

### Creation responses with one-time secrets (`POST`)

**Good** — flat resource at the root with the one-time `secret` as a sibling top-level field (`POST /v1/projects/{projectId}/api-keys`):

```json theme={null}
{
  "id": "key_01h455vb4pex5vsknk084sn02r",
  "projectId": "prj_01h455vb4pex5vsknk084sn02q",
  "organizationId": "org_01h455vb4pex5vsknk084sn02s",
  "name": "Production server key",
  "createdAt": "2026-11-22T10:00:00Z",
  "secret": "example_one_time_api_key_secret"
}
```

**Good** — flat webhook destination with the one-time `signingSecret` as a sibling field (`POST /v1/projects/{projectId}/destinations`):

```json theme={null}
{
  "id": "dst_01h455vb4pex5vsknk084sn02u",
  "projectId": "prj_01h455vb4pex5vsknk084sn02q",
  "url": "https://webhooks.example.com/events",
  "enabled": true,
  "createdAt": "2026-11-22T10:00:00Z",
  "signingSecret": "example_one_time_signing_secret"
}
```

**Bad** — two-key wrapper splitting the created resource and its one-time secret:

```json theme={null}
{
  "apiKey": {
    "id": "key_01h455vb4pex5vsknk084sn02r",
    "projectId": "prj_01h455vb4pex5vsknk084sn02q",
    "organizationId": "org_01h455vb4pex5vsknk084sn02s",
    "name": "Production server key",
    "createdAt": "2026-11-22T10:00:00Z"
  },
  "secret": "example_one_time_api_key_secret"
}
```

```json theme={null}
{
  "destination": {
    "id": "dst_01h455vb4pex5vsknk084sn02u",
    "projectId": "prj_01h455vb4pex5vsknk084sn02q",
    "url": "https://webhooks.example.com/events",
    "enabled": true
  },
  "signingSecret": "example_one_time_signing_secret"
}
```

### Collections vs. bare arrays

**Good** — collection wrapped in a top-level JSON object (`GET /v1/projects/{projectId}/api-keys`):

```json theme={null}
{
  "items": [
    {
      "id": "key_01h455vb4pex5vsknk084sn02r",
      "projectId": "prj_01h455vb4pex5vsknk084sn02q",
      "organizationId": "org_01h455vb4pex5vsknk084sn02s",
      "name": "Production server key",
      "createdAt": "2026-11-22T10:00:00Z"
    }
  ]
}
```

**Bad** — bare top-level JSON array:

```json theme={null}
[
  {
    "id": "key_01h455vb4pex5vsknk084sn02r",
    "projectId": "prj_01h455vb4pex5vsknk084sn02q",
    "organizationId": "org_01h455vb4pex5vsknk084sn02s",
    "name": "Production server key"
  }
]
```

### Allowed composite, nullable-subobject, and utility responses

**Good** — scalar utility response (`GET /v1/organizations/{organizationId}/projects/count`):

```json theme={null}
{
  "count": 42
}
```

**Good** — nullable sub-object paired with sibling metadata (`GET /v1/projects/{projectId}/subscription`):

```json theme={null}
{
  "subscription": null,
  "timeZone": "UTC"
}
```

**Good** — multi-entity composite response (`POST /v1/projects/{projectId}/exports`):

```json theme={null}
{
  "operation": {
    "id": "opr_01h455vb4pex5vsknk084sn02v",
    "status": "pending"
  },
  "resource": {
    "id": "prj_01h455vb4pex5vsknk084sn02q",
    "organizationId": "org_01h455vb4pex5vsknk084sn02s",
    "name": "Acme Billing"
  }
}
```

## Changelog

* **2026-11-22**: Approved and published as `ADS-0002`.

## Feedback

Found a Photon API that does not follow this standard, or have a suggestion to improve it? [Open an issue](https://github.com/photon-hq/api-design-standards/issues/new) in `photon-hq/api-design-standards` (we do not accept external pull requests).


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