---
title: "Overview"
description: "cs.api: every operation of the OpenAPI document as a typed call, available from @codespar/sdk 0.12.0."
---

{/* GENERATED by scripts/sdk-reference/generate.mjs from scripts/api-reference/openapi-snapshot.json and scripts/sdk-reference/intros/rest-client.md. Do not edit: run `npm run docs:sdk:generate`. */}

# REST client

**Available from `@codespar/sdk` 0.12.0, which is not on npm yet.** The published version today is 0.11.0, and it has no `cs.api`; 0.12.0 is on the `main` branch of [codespar-core](https://github.com/codespar/codespar-core). The examples below are not compiled against the installed package for that reason.

`cs.api` reaches every operation the API publishes at [`https://api.codespar.dev/openapi.json`](https://api.codespar.dev/openapi.json). No method on it is written by hand: the document is committed in the core as `openapi-snapshot.json`, the types under `src/generated/` are produced from it with openapi-typescript, and the client is typed by path and method. A path that does not declare the method does not compile, a missing required path parameter or body field does not compile, and the result is the documented 2xx shape.

```ts
import { CodeSpar } from "@codespar/sdk";

const cs = new CodeSpar({ apiKey: process.env.CODESPAR_API_KEY });

// Documented 2xx data, or a thrown CodesparApiError.
const wallets = await cs.api.get("/v1/wallets");

// Every documented status as a value, discriminated on `status`.
const payment = await cs.api.response("post", "/v1/wallets/{id}/execute", {
  path: { id: "wlt_0000000000000000" },
  body: {
    amount: 1,
    currency: "BRL",
    recipient: "recipient@example.com",
    description: "Example payment",
    mandate_id: "mnd_0000000000000000",
  },
});
if (payment.status === 402) {
  console.log("approval needed", payment.data);
}
```

## Calls

Two verbs and five shorthands, all on `cs.api`:

| Call | Returns | On a non-2xx status |
|---|---|---|
| `request(method, path, options?)` | the documented 2xx data (`ApiSuccess`) | throws `CodesparApiError`, parsed body on `e.body` |
| `get(path, options?)`, `post`, `put`, `patch`, `delete` | same as `request` with the method fixed | same |
| `response(method, path, options?)` | `{ status, ok, data, response }` for every status the document lists (`ApiResponse`) | returns it; only transport failures throw |

`options` carries `path`, `query`, `header` and `body` exactly as the document declares them, required where the document says so, plus the per-call `timeout` (milliseconds) and `signal`. When every option is optional the argument itself is optional. The `path` values are URL-encoded and expanded into the template before the request; a missing one throws before anything is sent. Operations documented as `text/event-stream` resolve to the raw `Response` once headers arrive; the body stays bound to `signal`, not to `timeout`.

Errors follow the rest of the SDK: a non-2xx from `request` is a [`CodesparApiError`](/docs/api/sdk/errors#codesparapierror) with `status`, `code` and `body`; a network failure is the same class with `status: 0`; a timeout is a [`TimeoutError`](/docs/api/sdk/errors#timeouterror).

The client only knows what the document says. A parameter a route accepts but does not declare is not typed here, and the fix is in the document, not in the package.

## `ApiClient`

The class behind `cs.api`. `new ApiClient({ baseUrl, apiKey, projectId?, timeout })` builds one with its own credentials; `ApiClient.operations()` lists every `{ method, path }` it can reach, in document order. The `x-codespar-project` header is sent when `projectId` is set, the same way the session client does it.

## `createApiClient`

`createApiClient(config)` returns a new `ApiClient` without a `CodeSpar` instance, for code that only ever talks REST. Same `ApiClientConfig` as the constructor.

## `API_OPERATIONS`

The generated table the client dispatches from: one `{ method, path, body, accept }` row per operation, where `body` and `accept` are the request and response content types the document declares. It is exported for tooling that wants to enumerate the surface; the client refuses a `method`/`path` pair that is not in it with an error naming the pair.

The types that go with these are exported too: `ApiPaths`, `ApiPath`, `ApiMethod`, `ApiOperation`, `ApiRequestOptions`, `ApiRequestBody`, `ApiResponse`, `ApiSuccess`, `ApiOperationRef`, `ApiPathsFor` and `ApiComponents` (the document's `components`), for typing a wrapper around the client.

## Operations by group

213 operations across 54 groups, the same groups as the [HTTP reference](/docs/api/reference). Each page shows the typed call for every operation and links to the HTTP reference section that carries the parameter tables and response shapes.

| Group | Operations |
|---|---|
| [Well-known documents](/docs/api/sdk/rest-client/well-known) | 2 |
| [Account Applications](/docs/api/sdk/rest-client/account-applications) | 1 |
| [Agents](/docs/api/sdk/rest-client/agents) | 4 |
| [Approvals](/docs/api/sdk/rest-client/approvals) | 3 |
| [Audit](/docs/api/sdk/rest-client/audit) | 1 |
| [Audit Events](/docs/api/sdk/rest-client/audit-events) | 6 |
| [Bank consents](/docs/api/sdk/rest-client/bank-consents) | 1 |
| [Cards](/docs/api/sdk/rest-client/cards) | 1 |
| [Cart](/docs/api/sdk/rest-client/cart) | 2 |
| [Commerce Memory](/docs/api/sdk/rest-client/commerce-memory) | 12 |
| [Connect](/docs/api/sdk/rest-client/connect) | 1 |
| [Connections](/docs/api/sdk/rest-client/connections) | 10 |
| [Consent Records](/docs/api/sdk/rest-client/consent-records) | 1 |
| [Consumer Mandates](/docs/api/sdk/rest-client/consumer-mandates) | 2 |
| [Consumers](/docs/api/sdk/rest-client/consumers) | 5 |
| [Contact Verifications](/docs/api/sdk/rest-client/contact-verifications) | 2 |
| [Counterparties](/docs/api/sdk/rest-client/counterparties) | 3 |
| [Boletos you owe (DDA)](/docs/api/sdk/rest-client/dda) | 4 |
| [Discovery](/docs/api/sdk/rest-client/discovery) | 1 |
| [Evaluations](/docs/api/sdk/rest-client/evaluations) | 1 |
| [Events](/docs/api/sdk/rest-client/events) | 1 |
| [Facilitator](/docs/api/sdk/rest-client/facilitator) | 2 |
| [Funding](/docs/api/sdk/rest-client/funding) | 1 |
| [Funding Sources](/docs/api/sdk/rest-client/funding-sources) | 1 |
| [Generate](/docs/api/sdk/rest-client/generate) | 1 |
| [Health](/docs/api/sdk/rest-client/health) | 1 |
| [Issuer](/docs/api/sdk/rest-client/issuer) | 1 |
| [KYC](/docs/api/sdk/rest-client/kyc) | 1 |
| [Mandates](/docs/api/sdk/rest-client/mandates) | 5 |
| [MCP Servers](/docs/api/sdk/rest-client/mcp-servers) | 8 |
| [Meta Tools](/docs/api/sdk/rest-client/meta-tools) | 1 |
| [OAuth](/docs/api/sdk/rest-client/oauth) | 4 |
| [Bank consents (legacy /ofb path)](/docs/api/sdk/rest-client/ofb) | 5 |
| [Spec](/docs/api/sdk/rest-client/openapi-json) | 2 |
| [Organizations](/docs/api/sdk/rest-client/organizations) | 1 |
| [Orgs](/docs/api/sdk/rest-client/orgs) | 15 |
| [Payment Links](/docs/api/sdk/rest-client/payment-links) | 5 |
| [Paywalls](/docs/api/sdk/rest-client/paywalls) | 4 |
| [Pix out](/docs/api/sdk/rest-client/pix-devolutions) | 1 |
| [Pix keys (DICT)](/docs/api/sdk/rest-client/pix-keys) | 3 |
| [Pix in](/docs/api/sdk/rest-client/pix-status) | 2 |
| [Policies](/docs/api/sdk/rest-client/policies) | 6 |
| [Policy Evaluations](/docs/api/sdk/rest-client/policy-evaluations) | 1 |
| [Projects](/docs/api/sdk/rest-client/projects) | 8 |
| [Providers](/docs/api/sdk/rest-client/providers) | 4 |
| [Receipts](/docs/api/sdk/rest-client/receipts) | 2 |
| [Sellers](/docs/api/sdk/rest-client/sellers) | 6 |
| [Servers](/docs/api/sdk/rest-client/servers) | 4 |
| [Sessions](/docs/api/sdk/rest-client/sessions) | 12 |
| [Tool Calls](/docs/api/sdk/rest-client/tool-calls) | 6 |
| [Triggers](/docs/api/sdk/rest-client/triggers) | 10 |
| [Wallets](/docs/api/sdk/rest-client/wallets) | 15 |
| [Webhook Endpoints](/docs/api/sdk/rest-client/webhook-endpoints) | 10 |
| [Whoami](/docs/api/sdk/rest-client/whoami) | 1 |

Versions: `@codespar/sdk` 0.11.0 on npm, 0.12.0 on `main`; the client exists from 0.12.0.

