# TypeScript SDK

import { Steps, Aside } from "@astrojs/starlight/components"

`@renai-labs/sdk` is the official TypeScript client for the Ren API. It's fully typed,
generated from the same OpenAPI spec that powers the [API reference](/docs/developers/api/).

## Install

```bash
npm install @renai-labs/sdk
```

## Quick start

<Steps>

1. **Create a client** with a base URL and an auth strategy:

   ```ts
   import { createRenClient, pat } from "@renai-labs/sdk"

   const client = createRenClient({
     baseUrl: "https://api.renai.build",
     auth: pat(process.env.REN_PAT_TOKEN!),
   })
   ```

2. **Call a resource.** Methods are grouped by resource and return
   `{ data, error, request, response }`:

   ```ts
   const { data: skills } = await client.skill.list()
   ```

</Steps>

Calls are grouped by resource: `client.agent`, `client.skill`, `client.mcp`,
`client.pod`, `client.project`, `client.session`, `client.trigger`, `client.vault`,
`client.credential`, `client.fileStore`, `client.memoryStore`, `client.environment`,
`client.replay`, `client.blueprint`, `client.registry`, `client.pat`. Each exposes the
operations available on that resource.

## Authentication

Authenticate with a [personal access token](/docs/developers/cli/) via the
`pat` strategy, for server-side, CLI, and CI usage:

```ts
import { createRenClient, pat } from "@renai-labs/sdk"

createRenClient({ baseUrl, auth: pat(process.env.REN_PAT_TOKEN!) })
```

## Errors

Non-2xx responses don't throw by default. Check `error`, or opt into throwing:

```ts
const { data, error } = await client.skill.get({ path: { id } })
if (error) {
  // error is typed to the operation's error schema
}

const { data } = await client.skill.get({ path: { id }, throwOnError: true })
```

## Configuration

`createRenClient` accepts any `@hey-api/client-fetch` `Config` option: `baseUrl`,
`headers`, `fetch`, `credentials`, interceptors, etc.

```ts
createRenClient({
  baseUrl: "https://api.renai.build",
  auth: pat(token),
  headers: { "X-Request-Id": crypto.randomUUID() },
  fetch: customFetch,
})
```

## Types only

For apps that only need the shapes (form validators, type exports), import from the
`/types` subpath to avoid pulling in the client runtime:

```ts
import type { Skill, SkillCreateData } from "@renai-labs/sdk/types"
```

<Aside type="note">
  Every method and type mirrors the [API reference](/docs/developers/api/). When the API adds an endpoint, a new SDK
  release exposes it on the matching resource.
</Aside>