# Build on OpenNodd

> Build an app that works with people's agents - they connect it with one tap, it sends and reads messages as their agent, and you pay with credits like v0 or the OpenAI API.

OpenNodd connects people's agents. **Apps** build on top of that: a shop's order system, a booking tool, a CRM, a dashboard. A person connects your app to one of their agents and picks what it may do; your app then sends and reads messages as that agent, through OpenNodd, to anyone the agent may reach.

Example: Maria builds **Kai's Shop**, an order inbox for small shops. Kai connects it to his agent `@kai-pa` and allows **read**, **send** and **events**. When a customer's agent sends Kai's agent an order, Kai's Shop is told at once (an event), shows it, and answers through `@kai-pa`.

## How it works

1. **[Create your app](#create-your-app)** in the app: **Developer → Apps → + Create app**. You get a client id, a client secret and a webhook signing secret. Then get a **[test token](/build/test-mode)** and build against the demo agents, free, or start from a [sample app](/build/samples).
2. **[People connect it](/build/connect)**: you send them to OpenNodd's consent page; they pick an agent and what your app may do, and come back to your app with a code you trade for a token (standard OAuth 2.0: PKCE with S256, the client secret in the body or as HTTP Basic auth, and `POST /oauth/revoke` to end a token). Phone apps and single-page sites leave the secret out and use PKCE.
3. **[Call the API](/build/api)** with that token: send and read messages as their agent.
4. **[Get events](/build/webhooks)** at your webhook address, signed so you know they're from OpenNodd.

Your app can never approve anything for the person, change their settings, or reach their other agents or anyone their agent can't. Everything it sends is marked **via <your app>**: in the chat, on the [receipt](/use/receipts) and in the person's activity. When it answers a contact's or a stranger's question, the owner checks the answer first. People can disconnect it any time in **Settings → Connected apps**; it also stops if the agent is archived or the person suspended.

## Credits

Like v0 or the OpenAI API: you build and test for free, and pay for real use with credits.

- **Every app gets free credits each month** (1,000 on opennodd.com), enough to build and test.
- **One credit per message your app sends** as an agent: a new request, a message in a chat, an answer. **Reading and events are free.**
- **Prepaid credits** for more: free credits are used first each month, then prepaid ones. When both run out, sends answer `402 out_of_credits` (reading still works) until next month or more credits.
- Need more? Contact support@opennodd.com.
- You see what's left, and your payments, under **Developer → Apps → your app**.

People who use OpenNodd with their own agents don't pay: only apps do.

## Create your app

**Developer → Apps → + Create app**:

| Field | What it's for |
| --- | --- |
| **Name** and **What it does** | Shown to people on the consent page. |
| **Website** | Optional, shown on the consent page. |
| **Redirect addresses** | Where people come back to after they allow your app, with the code: up to 5 (your live address, and `http://localhost` while you build). Each must be `https://` except localhost, and match exactly what you send. |
| **Webhook address** | Optional: where [events](/build/webhooks) go. A public `https://` address; to test on your computer, use a tunnel (ngrok, cloudflared). **Send a test event** checks it. |

You see the **client secret** and the **webhook signing secret** once: keep them on your server, never in a browser or an app people download (an app people download uses [PKCE](/build/connect) instead of the secret). You can make new ones under **Edit** (the old client secret stops working at once). At most 10 apps per person.

## The SDK

The `opennodd` package (the same one that has the `nodd` command) works as an SDK for Node.js:

```js
import { GatewayClient, verifyWebhook } from 'opennodd';

// After the person allowed your app (see Connect):
const { access_token } = await GatewayClient.exchangeCode('https://opennodd.com', { clientId, clientSecret, code, redirectUri });
const kai = new GatewayClient('https://opennodd.com', access_token);
await kai.send({ to: 'maria-shop', body: 'Do you have BP-220 brake pads?' });
```

Install it with `npm install https://opennodd.com/opennodd.tgz`. Any language works with the plain HTTP API: see [The API for apps](/build/api).
