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

# TypeScript SDK

> Raptora API-г төрөлтэйгээр дуудах албан ёсны client.

`@raptora/sdk` нь API-ийн бүх endpoint, хариуны төрлийг агуулна. Node 18+, Bun, Deno дээр ажиллана.

## Суулгах

**1. Package суулгах**

```bash npm theme={null}
npm install @raptora/sdk
```

```bash bun theme={null}
bun add @raptora/sdk
```

```bash pnpm theme={null}
pnpm add @raptora/sdk
```

**2. Key үүсгэх**

**Тохиргоо** → **API key** хуудаснаас **Key үүсгэх** дарна. Дэлгэрэнгүйг [API key](https://docs.raptora.io/api-reference/introduction.md#api-key) хэсгээс үзнэ.

**3. Орчны хувьсагчид хадгалах**

```bash .env theme={null}
RAPTORA_API_KEY=rpt_live_xxx
```

## Эхлэх

```ts theme={null}
import { createRaptora } from '@raptora/sdk'

const raptora = createRaptora({ apiKey: process.env.RAPTORA_API_KEY! })

const { data, error } = await raptora.calls.list({ query: { limit: 20 } })
if (error) throw new Error(error.title)

for (const call of data.data) {
  console.log(call.id, call.status)
}
```

## Resource-ууд

| Resource | Method |
| - | - |
| `raptora.phoneNumbers` | `list`, `retrieve` |
| `raptora.agents` | `list`, `retrieve`, `create`, `update`, `delete` |
| `raptora.calls` | `list`, `retrieve` |
| `raptora.chats` | `list`, `retrieve` |
| `raptora.grades` | `list`, `retrieve` |
| `raptora.criteria` | `list`, `retrieve`, `create`, `update`, `delete` |
| `raptora.projects` | `list`, `retrieve`, `create`, `update` |

```ts theme={null}
const agent = await raptora.agents.retrieve({ path: { id: agentId } })
const grade = await raptora.grades.retrieve({ path: { callId } })
```

## Төсөл

Байгууллагын key-ээр төсөл үүсгэж, жагсааж, аль ч төсөл дээр ажиллана. `project`-ыг заахгүй бол үндсэн төсөл.

```ts theme={null}
const org = createRaptora({ apiKey: process.env.RAPTORA_ORG_KEY! })

const { data: project } = await org.projects.create({ body: { name: 'Борлуулалт' } })
const { data: projects } = await org.projects.list()

const sales = createRaptora({ apiKey: process.env.RAPTORA_ORG_KEY!, project: project!.id })
await sales.agents.list()
```

## Агент удирдах

```ts theme={null}
const { data: agent } = await raptora.agents.create({
  body: { name: 'Борлуулалт', channels: ['VOICE'], instructions: 'Захиалга авна.' },
  throwOnError: true,
})

await raptora.agents.update({ path: { id: agent.id }, body: { status: 'LIVE' } })
await raptora.agents.delete({ path: { id: agent.id } })
```

## Үнэлгээний шалгуур

AI дуудлага бүрийг эдгээр асуултаар үнэлнэ. Дүн нь `raptora.grades`-аар ирнэ.

```ts theme={null}
const { data: criterion } = await raptora.criteria.create({
  body: { question: 'Агент мэндэлсэн үү?', weight: 1, critical: false },
  throwOnError: true,
})

await raptora.criteria.update({ path: { id: criterion.id }, body: { enabled: false } })
await raptora.criteria.delete({ path: { id: criterion.id } })
```

## Хуудаслалт

```ts theme={null}
let cursor: string | undefined
do {
  const { data } = await raptora.calls.list({ query: { limit: 100, cursor }, throwOnError: true })
  // data.data
  cursor = data.nextCursor ?? undefined
} while (cursor)
```

## Алдаа

Method бүр `{ data, error, response }` буцаана. `error` нь [алдааны хариу](https://docs.raptora.io/api-reference/introduction.md#алдаа)-тай ижил.

```ts theme={null}
const { error } = await raptora.calls.retrieve({ path: { id } })
if (error?.status === 404) {
  // олдсонгүй
}
```

Алдаа гарвал exception шидүүлэх бол `throwOnError: true` дамжуулна.

## Төрлүүд

Хариуны бүх төрөл export хийгдсэн.

```ts theme={null}
import type { Agent, AgentDetail, Call, CallDetail, Criterion, Grade, Problem } from '@raptora/sdk'
```

## Тохиргоо

| Сонголт | Утга |
| - | - |
| `apiKey` | `rpt_live_` эсвэл `rpt_test_` key. Заавал. |
| `baseUrl` | Анхдагч нь `https://api.raptora.io`. |
| `fetch` | Өөрийн `fetch` хэрэгжүүлэлт. |
| `headers` | Хүсэлт бүрт нэмэх header. |


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