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

# Test Your Integration

> Run your tests against a real gateway on stand-in plans.

The stub gateway is the real self-hosted gateway with stand-in plans behind it. Nothing reaches a provider and nothing is paid for, so you don't need a fake Dari.

```ts Node theme={null}
import { startStubGateway } from "@mupt-ai/dari-gateway/self_host/stub_gateway";

const dari = await startStubGateway({ plans: ["openai_codex"] });

// Point your app at it: gatewayUrl, clientId, clientSecret, redirectUri.
configure(dari.app);

// The user clicks Connect with Dari and approves. This is what your page gets:
const { code, codeVerifier } = await dari.connect();
await myApp.post("/api/dari/connect", { code, codeVerifier });

// Run what your app does, then check what reached the provider.
expect(dari.calls).toEqual([expect.objectContaining({ kind: "openai_codex", model: "gpt-5.5" })]);

await dari.stop();
```

```python Python theme={null}
import json, subprocess, requests

stub = subprocess.Popen(["npx", "dari-gateway-stub", "--plans", "openai_codex"],
    stdout=subprocess.PIPE, text=True)
dari = json.loads(stub.stdout.readline())

# Point your app at it: gatewayUrl, clientId, clientSecret, redirectUri.
configure(dari["app"])

# The user clicks Connect with Dari and approves. This is what your page gets:
approved = requests.post(f"{dari['controlUrl']}/connect").json()
my_app.post("/api/dari/connect",
    json={"code": approved["code"], "codeVerifier": approved["code_verifier"]})

# Run what your app does, then check what reached the provider.
calls = requests.get(f"{dari['controlUrl']}/served").json()["calls"]
assert [(call["kind"], call["model"]) for call in calls] == [("openai_codex", "gpt-5.5")]

stub.terminate()
```

```go Go theme={null}
stub := exec.Command("npx", "dari-gateway-stub", "--plans", "openai_codex")
out, _ := stub.StdoutPipe()
if err := stub.Start(); err != nil {
	t.Fatal(err)
}
defer stub.Process.Signal(os.Interrupt)

var dari struct {
	ControlURL string `json:"controlUrl"`
	App        struct{ GatewayURL, ClientID, ClientSecret, RedirectURI string }
}
json.NewDecoder(out).Decode(&dari)

// Point your app at it.
configure(dari.App.GatewayURL, dari.App.ClientID, dari.App.ClientSecret, dari.App.RedirectURI)

// The user clicks Connect with Dari and approves. This is what your page gets:
var approved struct {
	Code         string `json:"code"`
	CodeVerifier string `json:"code_verifier"`
}
res, err := http.Post(dari.ControlURL+"/connect", "application/json", nil)
if err != nil {
	t.Fatal(err)
}
json.NewDecoder(res.Body).Decode(&approved)
myApp.Connect(approved.Code, approved.CodeVerifier)

// Run what your app does, then check what reached the provider.
var served struct {
	Calls []struct{ Kind, Model string }
}
res, _ = http.Get(dari.ControlURL + "/served")
json.NewDecoder(res.Body).Decode(&served)
```

The Node tab runs the gateway inside a Bun test. Any other runner starts it as a process, as the Python and Go tabs do (`npm install -D @mupt-ai/dari-gateway`; Bun runs it): it prints one JSON line with `app` and a `controlUrl`, and `POST <controlUrl>/connect` answers `{"code", "code_verifier", "state"}`.

## What You Can Set Up

| Option | Does |
| - | - |
| `plans` | One stand-in plan each: `openai_codex`, `anthropic_claude_code` |
| `keys` | An API key each for the same user: `anthropic`, `openai`, `openrouter` |
| `models` | The models the gateway serves |
| `redirectUri` | The redirect URI `app` is registered with |

## What The User Does

The process form takes the same options as JSON on `POST <controlUrl>/connect`: `credential_ids`, `grant_id`, `deny`.

| Call | The user |
| - | - |
| `dari.connect()` | Shares everything your app can use |
| `dari.connect({ credentialIds: [dari.planIds[0]] })` | Shares only that plan |
| `dari.connect({ grantId })` | Changes an existing connection |
| `dari.connect({ deny: true })` | Denies. Rejects with `access_denied`, as `DariLink.open` does |

## Force An Error

| Call | Then |
| - | - |
| `dari.setState({ limited: true })` | Every plan is at its usage limit: requests are refused, and `plans[].state` goes `plan_limit` |
| `dari.setState({ weekly: 0.9 })` | Plans report 90% of the week used |
| `POST <controlUrl>/state` with the same JSON | The same, for the process form |
| [`revoke`](https://docs.dari.dev/link/manage-connections#disconnect) | The connection is gone: `unlinked` errors |


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