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

# Typed clients and the contract

> Name an app’s public functions in TypeScript and pin their calling contracts

## In the same repository

Set `"browserClient": true` in `bijection.json`. The app starter enables it.
`bijection dev` refreshes `.bijection/_generated/client.ts` as it prepares the
app. Run `bijection check --write-lock` to review changes to the lock.

```ts apps/main/src/client.ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { app, connect } from "../../../.bijection/_generated/client";

export { app };
export const client = connect(import.meta.env.VITE_BIJECTION_URL);
```

`client.mutate(app.notes.add, { text: "Hello" })` gets its argument type, answer
type and declared refusal payloads from the declaration. The generated module
carries the runtime validators and pins without bundling the app's server
code. Use `client.under(app.tenants.of(org))` to select a family member’s label.

## Calling contracts

`bijection check --write-lock` writes one `contract <path> <digest>` line per exposed function. Each digest covers the function’s kind, arguments, return value and declared refusals. Review the lock diff with the code change.

A generated client supplies a map of expected digests. It sends the entry for
the function it calls. If the entry is missing, the client refuses before
sending the request. When a reference comes from a different generated client,
its digest must match the connection's pin for that path. A mismatch returns `Conflict` with reason `ContractStale` before sending a request.

```ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { connect } from "@bijectionhq/bijection/client";

const client = connect(url, { contract: { "notes.add": digest } });
```

For a dynamic tool, pass `contract: "discover"` to call the serving interface
without a pin. Use `api("notes.list")` when you only know the path.
A dynamic call can return a host refusal or an application refusal. For
`kind: "app"`, the code is a string and the payload needs to be narrowed from
`unknown`.

`api<typeof App>()` supplies typed paths, arguments and wire-shaped answers.
A File in an answer comes back as its key string. To receive a File point,
declare the position with `t.file` and call through a generated reference or one
created with `api(appDeclaration)`.

A change to a pinned function returns `Conflict` with reason `ContractStale`. Adding a function or narrowing its roles leaves the other paths’ pins valid. Use `bijection deploy --trial` to list changes to existing contracts. For a production deployment, pass the reviewed paths as a comma-separated list to `--accept-breaking-contracts`.

A pinned mutation keeps its original session slot for retries on the same connection. Use the same `once` and call arguments to recover its ordered result while the registration and recovery authority are live.

## For another repository

```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
bijection client ts --out client --name @acme/orders-client
```

The package exports `app`, the typed reference tree, and `connect`, which supplies the digests from the reviewed lock. It also contains a language-neutral interface document. The command compares the lock’s per-path digests with the source before writing the package.

```ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { app, connect } from "@acme/orders-client";

const client = connect(process.env.ORDERS_URL!, { token });
const placed = await client.mutate(app.orders.place, { sku: "A-1", quantity: 2 });
```

For a language other than TypeScript, see [Other languages](https://docs.bijection.com/clients/openapi).


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