> This page is for version Preview.
> For other versions, use one of these documentation indexes:
> - Current (default): https://docs.paid.ai/current/llms.txt
> - Preview: https://docs.paid.ai/preview/llms.txt

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.paid.ai/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.paid.ai/_mcp/server.

# Expanding responses

> Get a referenced object in the same response, instead of its ID and a second request.

Objects on `https://api.paid.ai/v1` refer to each other by ID: a customer's `parent` is the ID of another customer. When you need the referenced object too, ask for it with `expand` and the response returns the full object in place of the ID, saving you a request per reference.

Use `expand` to:

* **Save round trips.** Get a customer and its parent customer in one call.
* **Read a chain of references.** Follow a reference on the object you expanded, up to two references deep.
* **Expand every item of a list.** On a list, each path applies to every object in `data`.

## How it works

Add `expand` to the query string with the path of the field to expand. Repeat it to expand several paths, up to 4 a request.

```bash
curl -G https://api.paid.ai/v1/customers/cus_8HqL2xT \
  -H "Authorization: Bearer $PAID_API_KEY" \
  --data-urlencode "expand=parent"
```

Without `expand`, `parent` is an ID:

```json
{ "parent": "cus_3Fw9KpR" }
```

With `expand=parent`, it is the parent customer:

```json
{
  "parent": {
    "id": "cus_3Fw9KpR",
    "object": "customer",
    "name": "Northwind Traders"
  }
}
```

A path names fields joined by dots, such as `field.nestedField`. Each step follows one reference, and a path can go at most two references deep. On a list, paths are relative to each item, so `expand=parent` on a customer list expands each customer's parent.

## What you can expand

Only some reference fields can be expanded. Each operation that takes `expand` lists the paths it accepts in the API Reference.

| Object             | Field                  | Expands to     |
| ------------------ | ---------------------- | -------------- |
| Customer           | `parent`               | Customer       |
| Customer           | `defaultPaymentMethod` | Payment method |
| Payment allocation | `payment`              | Payment        |

A field that is `null` stays `null` when you expand it. Setting a customer's `parent` through the API isn't available yet, so `parent` is `null` unless it was set elsewhere.

## What an expanded object follows

An expanded object is the same object its own retrieve endpoint returns, at your request's API version. Expanding it needs what retrieving it needs, so check your key before you add a path:

| You expand an object your request can't retrieve | Response                                                            |
| ------------------------------------------------ | ------------------------------------------------------------------- |
| Your API key lacks the object's scope            | `403` `insufficient_scope`, naming the scope to add.                |
| The object is in a beta you didn't opt in to     | `400` `beta_header_required`, naming the `Paid-Beta` value to send. |
| Your key is scoped to one customer               | `403` `customer_key_forbidden`, unless that object allows it.       |

A referenced object that no longer exists, or that your account can't see, stays an ID. The rest of the response is unchanged.

## Errors

A path that the operation doesn't accept, a path more than two references deep, or more than 4 paths returns `400` `invalid_request`, with `param` naming the `expand` value at fault, such as `expand` or `expand[1]`. A request that fails returns nothing else, so fix it and send it again.

## Related

* [Pagination](./pagination)
* [Betas and stability](/preview/developers/api/betas-and-stability)
* [Errors](/preview/developers/api/errors)
* [API Reference](./introduction)