> **Can't find what you're looking for?** Use `search_docs` on the docs MCP server at `https://docs.navalabs.ai/api/mcp` to find what you need.

# Partner integration \[Developer Preview]

Let your users set rules for their agents. Nava checks every action against those rules before it runs. See the [Integrator API reference](/api-reference/integrator) for every endpoint.

1. Your user saves a policy in Nava's embedded editor.
2. Your backend checks that the policy is active.
3. Your server sends each transaction to Nava before your agent acts.
4. Only approved transactions run.

Nava Gateway uses this same Integrator verification path for x402 payments. The
facilitator resolves an enrolled agent and active policy from the signed payer
wallet, then submits the payment with its integration API key and app ID.

## Configure

An integration admin creates the integration in Nava's `/integrations` view and registers your app's origin. The API key is shown once; store it as `NAVA_INTEGRATION_KEY`.

<div className="nava-full-table">
  | Variable | Value | Where |
  | --- | --- | --- |
  | `NAVA_INTEGRATION_KEY` | Shown once when you create the integration | Server only (secret) |
  | `NAVA_API_URL` | `https://internal.navalabs.dev/api` | Server |
  | `NAVA_APP_ID` | Your integration's public app ID | Browser and server |
  | `NAVA_APP_URL` | `https://app.navalabs.dev` | Browser |
</div>

The integration-mode `NavaClient` has no default API URL, so always pass `NAVA_API_URL` as `baseUrl`.

Keys are verify-only by default. That is enough for the ordinary embed flow below. Extra privileges (elevated write scopes, or wallet sign-up that skips the funds check) require the Nava team to allow them on the integration, then a **new** API key that includes those scopes.

## Who can sign in

When a user opens the embedded editor, Nava signs them in inside its own popup. Your app never handles Nava passwords or tokens.

* **Existing Nava users** can always sign in, by email or wallet.
* **New users by wallet (recommended for most partners)** can create a Nava account if their wallet holds Nava's minimum native ETH on the configured chains. Ask Nava for the current amount. This works with a public, `appId`-only login context — no special API key scope and no partner backend for admission. Users below the minimum see a message in the popup, and the embed surfaces an `ineligible` error.
* **New users by email** can sign up only after Nava adds each email to its allowlist. That does not suit open onboarding.

Most partners should use the wallet-with-funds path and leave advanced sign-up off.

### Advanced: partner-vouched wallet sign-up

If you need to onboard wallets that may not hold the minimum yet, ask the Nava team to enable **Advanced: wallet sign-up** (`integrator:users:signup`) on your integration, then create a new integration key that includes that scope. Existing keys do not gain it.

With that key on your server only, mint a login context bound to a wallet the user has proved to you (`signup: true` and `walletAddress`). New users who complete Nava sign-in with that wallet skip the funds check. Public `appId`-only contexts never skip it.

Bind only a wallet the user controls in their browser. Nava's login popup signs with that wallet and refuses any other signer, so a server-held key cannot complete signup.

Mint the context on your backend and return only `{ id, state }` to the browser:

```ts
const response = await fetch(`${NAVA_API_URL}/embed/login-contexts`, {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'x-app-id': NAVA_APP_ID,
    'x-api-key': NAVA_INTEGRATION_KEY, // Server only.
  },
  body: JSON.stringify({
    appId: NAVA_APP_ID,
    parentOrigin: PARTNER_ORIGIN, // Exact origin registered on the integration.
    signup: true,
    walletAddress, // Wallet the user proved to your backend.
  }),
});
if (!response.ok) throw new Error('Nava refused the login context.');
const { id, state } = await response.json();
```

Pass that context into the embed with `getLoginContext`:

```tsx
<NavaPolicyProvider
  appId={NAVA_APP_ID}
  baseUrl={NAVA_APP_URL}
  onComplete={onPolicyComplete}
  getLoginContext={async () => {
    const { id, state } = await fetchSignupLoginContext(); // Your backend route.
    return { id, state };
  }}
>
  <NavaPolicyButton />
  <NavaPolicyWidget />
</NavaPolicyProvider>
```

Requires `@navalabs/sdk` 0.17.2 or later.

## Client-side instructions

These steps run in your app's browser. Your frontend embeds Nava's editor and sends policy-completion events and trade requests to your backend.

### Embed the editor

Install the SDK (React 18 or later) and wrap your app once in `NavaPolicyProvider`. Everything else goes inside it.

```bash
npm install @navalabs/sdk
```

```tsx
import {
  NavaPolicyButton, NavaPolicyProvider, NavaPolicyWidget,
} from '@navalabs/sdk/react';

<NavaPolicyProvider
  appId={NAVA_APP_ID}
  baseUrl={NAVA_APP_URL}
  onComplete={onPolicyComplete}
>
  <NavaPolicyButton />
  <NavaPolicyWidget />
</NavaPolicyProvider>
```

`onPolicyComplete` is your frontend callback. Send the completion to a route on your backend, which runs the [policy check](#check-the-user-has-a-policy) and returns the result to your UI.

`onComplete` receives `{ appId, agentId, policyId, version, walletAddresses }`. Use `walletAddresses` for the policy check and for trades; Nava finds the agent from the wallet (see [Agent resolution](/introduction/key-terms#agent-resolution)).

Returning users stay signed in. The editor keeps its own Nava session inside its frame and restores it on reload, so your app never stores Nava tokens.

The editor's credentials can read **and change** the user's agents, wallets and policies. Nava issues them only after the user signs in and consents in Nava's popup, and binds each one to that user and your integration, so it reaches only the agents the user connected to your app. No partner API secret is involved; your browser code uses only the public `NAVA_APP_ID`.

| Element | What it does | Props |
| --- | --- | --- |
| `NavaPolicyProvider` | Holds the editor drawer. Wrap your app once. | `appId`, `baseUrl`, `onComplete`; optional `agentId`, `theme` (`dark` or `light`), `zIndex`, `onOpenChange`, `getLoginContext` |
| `NavaPolicyButton` | Opens the editor. | Optional label (children), `className`, `style` |
| `NavaPolicyWidget` | Shows the user's policy checks. | Optional `minHeight`, `className`, `style` |
| `NavaPolicyEditor` | The editor inline, without the provider or drawer. | `appId`, `baseUrl`, `onComplete`; optional `agentId`, `theme`, `minHeight`, `getLoginContext` |
| `useNavaPolicyDrawer()` | Returns `open`, `close` and `isOpen`. | |
| `useNavaPolicyWidget()` | Returns `refresh`. | |

Open the editor from your own link or button:

```tsx
import { useNavaPolicyDrawer } from '@navalabs/sdk/react';

function PolicyLink() {
  const { open } = useNavaPolicyDrawer();
  return (
    <button type="button" className="link" onClick={open}>
      Set your guardrails
    </button>
  );
}
```

### Refresh the widget

The widget loads once. `submitTrade()` below is your frontend helper that calls your backend. Refresh the widget after that request returns:

```tsx
const { refresh } = useNavaPolicyWidget();
await submitTrade();
refresh();
```

## Server-side instructions

These steps run on your partner backend. Keep `NAVA_INTEGRATION_KEY` here and use `NAVA_API_URL` for calls to Nava. Your frontend calls your backend; your backend calls Nava's Integrator API.

### Create the Nava client

Construct the integration-mode client on your server:

```ts
// [!include ~/../examples/partner-demo/server/nava.ts:nava-client]
```

### Partner management consent

To manage agents and wallets from your backend, ask the user to grant `integrator:agents:write` and `integrator:wallets:write`. Enable the needed scopes on the integration and its API key first. The basic editor above can still edit policies without this backend handoff.

Create a login-context endpoint in your backend. Authenticate it with your existing partner session and derive `partnerUserRef` from that session. Use your configured, registered partner origin; do not trust a user reference or arbitrary origin supplied by the browser.

```ts
import type { IntegrationKeyConfig, IntegrationScope, NavaClient } from '@navalabs/sdk';

const requestedScopes: readonly IntegrationScope[] = [
  'integrator:agents:write',
  'integrator:wallets:write',
];

async function createPartnerLoginContext(
  client: NavaClient<IntegrationKeyConfig>,
  session: { partnerUserRef: string },
  registeredParentOrigin: string,
) {
  const { id, state } = await client.createLoginContext({
    parentOrigin: registeredParentOrigin,
    partnerUserRef: session.partnerUserRef,
    requestedScopes,
  });
  return { id, state };
}
```

Your authenticated `POST /api/nava/login-context` route calls this function with the integration-mode client above and returns its result with `Cache-Control: no-store`. `partnerUserRef` is your stable user identifier, trimmed to 1 to 128 characters. The context expires at `expiresAt`; its single-use `state` is returned only on creation. Keep that state out of logs, analytics, URLs and error output. Creating a context does not grant access.

Pass a callback to the provider so the SDK hands the context to Nava's editor:

```tsx
import {
  NavaPolicyButton, NavaPolicyProvider,
  type NavaLoginContext,
} from '@navalabs/sdk/react';

async function getLoginContext(): Promise<NavaLoginContext> {
  const response = await fetch('/api/nava/login-context', { method: 'POST' });
  if (!response.ok) throw new Error('Could not create consent context');
  return response.json();
}

<NavaPolicyProvider
  appId={NAVA_APP_ID}
  baseUrl={NAVA_APP_URL}
  getLoginContext={getLoginContext}
  onComplete={onPolicyComplete}
>
  <NavaPolicyButton />
</NavaPolicyProvider>
```

The inline `NavaPolicyEditor` accepts the same callback. Your browser calls your backend; the integration key stays on the server. Nava asks the user to sign in and Allow the requested scopes. Each management call then checks the key, integration configuration and user's current grant.

### Manage agents and wallets

After consent, list the user's agents. Reuse the agent selected in the editor when it is the one your application needs:

```ts
const agents = await client.listAgents({ partnerUserRef: session.partnerUserRef });
```

For a new bot, create an agent and register its execution wallet once. Persist each returned ID in your backend before the next write:

```ts
const partnerUserRef = session.partnerUserRef;
const agent = await client.createAgent({ partnerUserRef, name: 'Trading bot' });
// Store agent.id before registering the wallet.
const wallet = await client.registerWallet({
  partnerUserRef,
  agentId: agent.id,
  address: executionWalletAddress,
  chainId: 1,
  label: 'Ethereum trading wallet',
});
```

`chainId` must be a positive integer when supplied. Omit it only when you intend an all-chains registration, returned as `chainId: null`. Registration starts with `verificationStatus: 'pending'`; registering an address does not prove your signer's authority or create an active policy. For a new agent, open the editor with its `agentId` and have the user save a policy before enabling transactions.

Address rotation changes only `address`, preserves the chain and label, and resets verification to pending with `verifiedAt: null`. Sending the same address leaves verification unchanged:

```ts
const updatedWallet = await client.updateWallet({
  partnerUserRef,
  agentId: agent.id,
  walletId: wallet.id,
  address: replacementWalletAddress,
});
```

To remove a wallet when it is no longer needed:

```ts
await client.removeWallet({ partnerUserRef, agentId: agent.id, walletId: wallet.id });
```

`removeWallet` resolves without a value. The [TypeScript reference](/sdk/typescript#partner-management) lists all six methods and their types; the [HTTP reference](/api-reference/integrator#partner-management) documents scopes and response envelopes.

### Recover access and uncertain writes

On `403 grant_revoked`, reopen the editor to ask the user for consent again. A plain `403 forbidden` means the key lacks a required scope and needs a configuration change. `404 not_found` from `listAgents` means no active grant covers the user/scope, or the integration no longer allows it; check allowed scopes if re-consent does not help. A wallet-operation `404` can instead mean the resource is missing or inaccessible.

Agent names are not unique and management creation has no idempotency key. Serialize creation in your backend and store the returned IDs. After an uncertain agent or wallet creation, read the user's agents once to recover a committed result. An empty read cannot rule out a write still in flight: retain it as pending for reconciliation instead of automatically sending another POST. Verification's `Idempotency-Key` does not apply to management.

The [complete SDK management example](https://github.com/navalabs-dev/sdk/blob/ba135ce042b7e137978bc6bd497dcf5038fb9bd1/packages/sdk/examples/partner-management.ts) shares recovery across agent and wallet creation and continues into the transaction flow. Its creation helpers require backend serialization and durable pending-operation tracking.

### Check the user has a policy

**Run this check server-side, on your partner backend.** When the browser receives `onComplete`, call your backend to read the wallet's policy using the integration-mode `NavaClient`. Keep `NAVA_INTEGRATION_KEY` on the server. Enable trading only after the backend confirms the policy is active.

Nava enforces the user's current policy on every verification.

```ts
// [!include ~/../examples/partner-demo/server/nava.ts:check-policy]
```

:::details[Server-side request with curl]
```bash
curl "$NAVA_API_URL/integrator/policies?walletAddress=0xYourUserWallet" \
  -H "x-app-id: $NAVA_APP_ID" \
  -H "x-api-key: $NAVA_INTEGRATION_KEY"
```

```json
{
  "status": "active",
  "policyId": "1e957416-…",
  "version": 1,
  "document": { … }
}
```
:::

### Submit a trade

Run the transaction-building and Nava verification code below on your backend when your frontend requests a trade.

```ts
// [!include ~/../examples/partner-demo/server/agent/swap.ts:submit-trade]
```

`waitForVerification` returns once Nava approves or rejects. Execute only if it is approved. To retry, send the same `idempotencyKey` with the same transaction; see [Retries](/api-reference/integrator#retries).

:::details[Server-side request with curl]
```bash
curl -X POST "$NAVA_API_URL/integrator/verifications" \
  -H "x-app-id: $NAVA_APP_ID" \
  -H "x-api-key: $NAVA_INTEGRATION_KEY" \
  -H "Idempotency-Key: swap-123" \
  -H "Content-Type: application/json" \
  -d '{
    "escrowAddress": "0xYourUserWallet",
    "prompt": "Swap 5 USDC for USDT",
    "proposedTx": { "protocol": "uniswap_v3", "chainId": 1,
      "to": "0x66a9…", "value": "0", "data": "0x3593…" }
  }'
```

```json
{
  "id": "ff845a3f-…",
  "status": "PENDING",
  "canExecute": true,
  "verdict": { "outcome": "approved", "reasonCode": "allowed", … }
}
```

If `verdict` is still `null`, poll until it is set:

```bash
curl "$NAVA_API_URL/integrator/verifications/ff845a3f-…" \
  -H "x-app-id: $NAVA_APP_ID" \
  -H "x-api-key: $NAVA_INTEGRATION_KEY"
```

The response has the same shape.
:::

## Example prompts

Save a Spot swapper policy with USDC, USDT and a $100 cap, then try:

| Prompt | Result |
| --- | --- |
| Swap 5 USDC for USDT on Uniswap (Ethereum). | Approved |
| Swap 200 USDC for USDT on Uniswap (Ethereum). | Rejected: over the cap |
| Buy $20 of ETH on Hyperliquid testnet. | Refused: not in the policy |

Test wallets need no funds. By default nothing is signed or sent.
