---
title: Spaces
description: "Give each of your customers their own account. How an organization, its projects, the Space a project belongs to and each customer account fit together, what runs in Test today, and why a Collect charge always names its consumer_id."
---

import { Callout } from "fumadocs-ui/components/callout";

**Spaces** is how a company that serves its own customers gives each one of
them an account of their own. Money a customer receives lands in that
customer's account, not in yours and not in another customer's (today, in Test
only: see [Test and Live](#test-and-live)). A SaaS, an
agency or an app that operates on behalf of many businesses uses Spaces when
each business needs its own balance and history.

If you only need to tell your customers' agent sessions apart, you do not need
Spaces: session metadata does that. The
[Multi-Tenant cookbook](/docs/cookbooks/multi-tenant) explains which of the two
you need.

## The four levels

| Level | What it is | How many |
|---|---|---|
| **Organization** | Your CodeSpar account: members, roles, and whether it is a person (PF) or a company (PJ) | Your CodeSpar account |
| **Project** | An environment of your organization, Test or Live, fixed when the project is created. API keys belong to a project | One or more per organization |
| **Space** | The regulated operation a project's accounts belong to. Each project that holds accounts at the licensed partner belongs to one Space in its environment | A project belongs to at most one; one Space serves many projects |
| **Customer account** | One of your customers' own account, bound to one project | At most one open per customer per project |

Your customer (a person or a company) is a **consumer** of your organization.
A customer account links that consumer to an account opened for them in a
project. Test and Live never share a customer account: an account opened in a
Test project stays in that project and never moves to Live.

## Test and Live

**Test** is where you start. A Test project opens customer accounts in the
licensed partner's sandbox, with synthetic data that CodeSpar generates. Nobody's
identity is checked and no real money moves. Trying it does not require a Space
request: it uses the project's own sandbox access. The
[first customer guide](/docs/cookbooks/spaces-first-customer-test) walks through
it in the dashboard.

**Live** exists too, with real accounts and real verification. Activation of a
Live Space goes through the CodeSpar team, and this page does not cover it.
Charging into a customer's own account is Test only today: in Live, a Collect
link that names any consumer other than your organization's own account is
refused when it is created, with `422 receiving_identity_missing`, and
`GET /v1/collect/receivers` lists only the organization's account.

## Who can open customer accounts

- **A company organization.** Spaces is for organizations declared PJ. In a PF
  organization the dashboard shows the Spaces item locked, and the Spaces routes
  answer `403 account_type_not_eligible`.
- **The titular.** The titular is the person who created the organization. Only
  the titular, holding the Owner or Admin role in the project, sees and opens
  customer accounts. Titular is a dashboard role: it does not make that person the owner
  of the money, and it is unrelated to the holder of any account.
- **A Test project whose sandbox access is active.** In Test the Space needs no
  activation or request: the platform prepares the project's sandbox access by
  itself, for every organization, in seconds. While it is being prepared, the
  dashboard shows no button to open an account, and a request is refused with
  `403 onboarding_capability_inactive`. If it is still being prepared after about
  a minute, contact CodeSpar. The guide's
  [first section](/docs/cookbooks/spaces-first-customer-test#before-you-start-the-projects-sandbox-access)
  shows what the dashboard says meanwhile.

## What the API does and what only the dashboard does

Today, opening and operating customer accounts is a dashboard action by a
signed-in person, with one exception for test balance. Charging into a customer
account is an API call.

| Action | Where, today |
|---|---|
| Open a customer account in Test | Dashboard only. In a Test project, `POST /v1/account-applications` answers `403 sandbox_onboarding_synthetic_only` |
| See customer accounts, their status and balances | Dashboard only, for the titular |
| Add test balance | Dashboard, or API: `POST /v1/account/fund/sandbox` with a key holding the `consumers:fund` scope |
| Pause, resume, end an account's binding | Dashboard only |
| List the consumers that can receive a charge, with their `consumer_id` | API: `GET /v1/collect/receivers` |
| Charge into a customer's account | API: `POST /v1/collect/links` with `consumer_id`. Today, Test only |

The `403 sandbox_onboarding_synthetic_only` is a CodeSpar rule, applied before
anything reaches the partner: in a Test project, accounts are opened only with
synthetic data, so a real CPF or CNPJ typed into a request is never sent to open
one. In a Test project, the dashboard is the way to open a customer account.

## Always pass `consumer_id`

<Callout type="warn" title="Name the receiver on every charge">
A Collect link that omits `consumer_id` does not know which of your customers
it is for, so Collect chooses the receiver:

- With a default receiver configured, every unnamed charge goes to it, one
  consumer for the whole project, whatever customer it was meant for. A default
  that is no longer eligible is refused with `409 collect_receiver_default_ineligible`.
- Without a default, Collect uses the only eligible receiver when there is
  exactly one, silently. The project's own Test account is eligible too, so
  after your first customer account there are usually two, and an unnamed link
  is refused with `409 collect_receiver_unresolved`. Zero eligible receivers get
  the same 409.

Pass the customer's `consumer_id` on every link you create for that customer.
A default receiver does not fix this: it applies to the whole project, not to
one customer.
</Callout>

```bash
curl -X POST https://api.codespar.dev/v1/collect/links \
  -H "Authorization: Bearer $CODESPAR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "consumer_id": "cus_000000000000000000000000",
    "version": {
      "title": "Order 4417",
      "items": [{ "name": "Monthly plan", "quantity": 1, "unit_amount_minor": 4990 }],
      "surfaces": ["page"],
      "due_in_days": 3
    }
  }'
```

`GET /v1/collect/receivers` lists the consumers a link may name, each with its
`consumer_id`, a `label` (the customer name you typed in the dashboard) and
`eligible`. Creating the link does not check the receiver: an explicit
`consumer_id` is checked when the link is published, and one that cannot
receive is refused with `422 receiving_identity_missing`. See
[Collect](/docs/concepts/collect) for the rest of the link.

## In the API and the code

The names differ in a few places, so a short map:

- A customer account's id starts with `spc_`. Its consumer's id, the one Collect
  takes as `consumer_id`, starts with `cus_` for customers opened in the
  dashboard.
- A customer account's status is `draft`, `verifying`, `active`, `suspended` or
  `closed`. A new Test account starts as `draft` and becomes `active` when the
  sandbox opens it.
- The routes under `/v1/spaces` serve the dashboard and do not accept an API key.

## Next steps

<NextStepsGrid items={[
  { label: "COOKBOOK", title: "Your first customer in Test", description: "Open a synthetic customer account from the dashboard, step by step.", href: "/docs/cookbooks/spaces-first-customer-test" },
  { label: "COOKBOOK", title: "Multi-Tenant Agent", description: "Session metadata or customer accounts: which one your SaaS needs.", href: "/docs/cookbooks/multi-tenant" },
  { label: "CONCEPT", title: "Collect", description: "Charge into a customer account with an explicit consumer_id.", href: "/docs/concepts/collect" },
  { label: "CONCEPT", title: "Test mode", description: "What a Test project can and cannot do.", href: "/docs/concepts/test-mode" },
]} />
