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

# Partner integration

> Offer Kash prediction markets inside your own app, to your own users, through the REST API.

A partner is a company that offers Kash markets to its own users from its own app. You build the interface. Your server calls the [REST API](https://docs.kash.bot/developer-docs/rest-api/overview.md) with one **partner key**, and creates a Kash account for each user who opts in. The API then trades for that account on your instruction, pays its winnings into it, and sends its withdrawals to the address you registered for the user.

This section is written for the engineers who build that integration. In the examples the partner is a fictional sports app, Harbour Sports Picks.

## Concepts

| Concept | What it is |
| - | - |
| **Partner organisation** | Your company on Kash. Partner keys, accounts and webhooks all belong to it. |
| **Partner key** | An API key that belongs to your organisation and has no user of its own. A test key starts `kash_test_` and works on staging; a live key starts `kash_live_` and works in production. See [Keys, approval and IP allowlists](https://docs.kash.bot/developer-docs/partner-integration/keys.md). |
| **Partner account** | The Kash account of one of your users. You create it with your own id for the user (`externalId`), and the API answers with its `accountId`. See [Accounts](https://docs.kash.bot/developer-docs/partner-integration/accounts.md). |
| **`Kash-Account` header** | How a partner key says which account a call is for. Send `Kash-Account: <accountId>` on balance, trade, portfolio, position, redemption and trace calls. |
| **Deposit address** | The account's own Solana wallet. You fund it by sending USDC on Solana to this address. |
| **Destination** | The user's own address in your app, on Solana or on Arc. Withdrawals go only there. |

One key acts for every one of your users, the pattern of Stripe Connect's `Stripe-Account` header. A key per user would put thousands of secrets on the same server without narrowing what a breach exposes. What bounds a leaked partner key is the rule that money leaves an account only to that user's registered destination, together with the request [rate limits](https://docs.kash.bot/developer-docs/partner-integration/rate-limits.md), suspension of one account in one call, and the 24-hour hold on withdrawals after a destination change.

## Who does what

| | You | The API |
| - | - | - |
| Keys | Ask ZeroID for a test key, then for approval and a live key. Rotate your webhook secret from your server. | ZeroID issues, changes and revokes partner keys, their webhook URLs and IP allowlists. |
| User interface | Build every screen your users see. | Provides no interface for partner users. |
| Accounts | Collect each user's consent and true country, then create the account. | Sets up the account and its Solana wallet, and tells you when it is ready. |
| Funding | Move each user's USDC from wherever your platform holds it to the account's Solana deposit address. | Does not bridge funds in, and does not notify you of deposits. |
| Trading | Send the user's trade instructions. | Executes them on the Kash protocol and reports each outcome by webhook. |
| Winnings | Nothing. | Pays a resolved market's winnings into the account automatically and sends `payout.completed`. |
| Withdrawals | Request them, with an amount. | Sends the USDC to the destination you registered: directly on Solana, or through the Relay bridge to Arc. |
| Network fees | Nothing for trades. | ZeroID pays the Solana network fee of trades. A withdrawal's network fee is charged to the account in USDC (see [Withdrawals](https://docs.kash.bot/developer-docs/partner-integration/withdrawals.md)). |
| Support | Support your users for everything on your side, including moving their funds into their accounts. | ZeroID support helps you with the API and your accounts. |

## Where the money is

* An account's USDC and positions are held on chain, in that account's own Solana wallet. Your server never holds a key to it.
* The API moves funds out of an account only to carry out the trades and withdrawals you request, and to charge a withdrawal's network fee. A withdrawal always goes to the user's registered destination: the request cannot name another address.
* Partner accounts have no per-trade or daily spending caps, the same as a user of the Kash web app.
* A user has no Kash login yet, so they reach their account only through your app. That is why an account must be empty before you can [release](https://docs.kash.bot/developer-docs/partner-integration/release.md) it.

## The flow

**1. Get a test key**

Ask ZeroID for a staging partner key, and send your webhook URL. See [Keys](https://docs.kash.bot/developer-docs/partner-integration/keys.md).

**2. Create an account**

`POST /v1/partner/accounts` when a user opts in. You receive `account.active` with the account's Solana `depositAddress`.

**3. Fund it**

Send USDC on Solana to the deposit address, then read `GET /v1/balance`. On staging, ZeroID funds test accounts with test USDC on request.

**4. Trade**

Read markets and quotes, then `POST /v1/trades` with the `Kash-Account` header. Outcomes arrive by webhook.

**5. Withdraw**

Quote, then `POST /v1/partner/accounts/{accountId}/withdrawals`. The USDC goes to the user's registered destination.

**6. Go live**

Ask ZeroID to approve your organisation and send your IP allowlist and production webhook URL. ZeroID issues your live key; then switch your base URL. See the [go-live checklist](https://docs.kash.bot/developer-docs/partner-integration/go-live.md).

## Base URLs

| Environment | Base URL | Network | Keys |
| - | - | - | - |
| Staging (sandbox) | `https://api-staging.kash.bot/v1` | Solana devnet, test USDC | `kash_test_` |
| Production | `https://api.kash.bot/v1` | Solana mainnet, real USDC | `kash_live_` |

## SDK

The TypeScript examples in this section use [`@kashdao/sdk`](https://docs.kash.bot/developer-docs/rest-api/sdks/typescript) version **0.4.0**, the first version with the partner methods (`kash.partnerAccounts`, `kash.balance` and the `account` option for acting for one account) and the partner webhooks. Earlier versions have none of these. Every route also works over plain HTTP, as the `curl` examples show.

```bash theme={null}
npm install @kashdao/sdk@^0.4.0
```

For a complete working example, the [partner integration sample](https://github.com/KashDAO/partner-integration-sample) creates an account, checks its balance, places a trade, withdraws and receives verified webhooks, one script per step.

| Import from | What it holds |
| - | - |
| `@kashdao/sdk` | `KashClient`, errors and error codes, guards, and the types of markets, trades, quotes, portfolio, traces and webhooks. Most integrations import only from here. |
| `@kashdao/sdk/partner` | Types of the partner surface: accounts, balances, withdrawals and their results. Types only; the methods are on `KashClient`. |
| `@kashdao/sdk/schemas` | Every Zod schema, for validating data yourself. The client already validates each response with them. |
| `@kashdao/sdk/webhooks` | The partner webhook payload types and schemas. |

The SDK picks the base URL from the key's prefix.

## Next

> [card] [Quickstart](https://docs.kash.bot/developer-docs/partner-integration/quickstart.md)
>
> Create an account, fund it, trade and withdraw on staging.

> [card] [Keys and approval](https://docs.kash.bot/developer-docs/partner-integration/keys.md)
>
> Test and live keys, approval and the IP allowlist.


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