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

# SDK Quickstart

> Use the Simple AI SDK from code actions or your own applications

The Simple AI SDK (`@simple-ai-lab/sdk`) is a typed TypeScript client for the Simple AI API. It works in two places:

* **Inside [code actions](/code-actions)** — preinstalled and authenticated automatically; just import it.
* **In your own applications** — install it from npm and authenticate with an API key.

## Inside a Code Action

No installation or keys needed. The handler's `client` is ready to use:

```typescript theme={null}
import { defineAction } from '@simple-ai-lab/sdk';

export default defineAction(async ({ inputs, client }) => {
  const { records, total } = await client.data.query({
    tableName: 'orders',
    text: inputs.orderNumber,
    size: 5,
  });
  return { total, orders: records };
});
```

## In Your Own Application

```bash theme={null}
npm install @simple-ai-lab/sdk
```

Create an API key in the dashboard under **Settings → API Keys**, then:

```typescript theme={null}
import { SimpleAI } from '@simple-ai-lab/sdk';

// Reads SIMPLE_API_KEY from the environment by default
const client = new SimpleAI();

// Or pass it explicitly
const explicit = new SimpleAI({ apiKey: process.env.MY_SIMPLE_KEY });
```

## Error Handling

Every non-2xx API response throws a `SimpleAIError` with the HTTP `status`, a machine-readable `code` when available, and the parsed response `body`:

```typescript theme={null}
import { SimpleAI, SimpleAIError } from '@simple-ai-lab/sdk';

const client = new SimpleAI();
try {
  await client.data.get('customers', 42);
} catch (e) {
  if (e instanceof SimpleAIError && e.status === 404) {
    // record does not exist
  } else {
    throw e;
  }
}
```

## What's Included Today

* **`client.data`** — full custom data access: [query, records, bulk upserts, and tables](/sdk/data)
* **`defineAction`** — typed code-action handlers

The SDK will grow to cover more of the platform (agents, calls, contacts) — the same `client` object will gain new namespaces.
