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

# 자원 관리(REST)

> SDK의 TelloApi로 도구·에이전트·크루를 만들고 고치고, 목표로 크루를 만들고, 통화 초안을 확정해요.

## 할 수 있는 일

실시간 통화는 WebSocket 클라이언트(`TelloClient`)가 맡고, 도구·에이전트·크루 같은 자원 관리는
REST 클라이언트 `TelloApi`가 맡아요. `TelloApi`는 [REST API](https://docs.telloai.io/developer/rest/overview.md)를 그대로
부르는 얇은 클라이언트예요. 요청·응답 칸은 REST 문서와 같아요.

| 자원 | 메서드 | REST 문서 |
| - | - | - |
| 도구 | `tools.list` · `get` · `create` · `update` · `delete` | [도구](https://docs.telloai.io/developer/rest/tools.md) |
| 에이전트 | `agents.list` · `get` · `create` · `update` · `delete` | [에이전트](https://docs.telloai.io/developer/rest/agents.md) |
| 크루 | `crews.list` · `get` · `create` · `update` · `delete` · `generate` · `generateAndWait` | [크루](https://docs.telloai.io/developer/rest/crews.md) |
| 크루 생성 작업 | `crewGenerations.get` | [목표로 크루 만들기](https://docs.telloai.io/developer/rest/crews.md#목표로-크루-만들기) |
| 통화 초안 | `callDrafts.create` · `revise` · `confirm` | [통화 초안](https://docs.telloai.io/developer/rest/call-drafts.md) |

이름은 언어 관례를 따라요. Python은 `crew_generations`·`call_drafts`·`generate_and_wait`, Go는
`api.Tools.Create`·`api.CallDrafts.Confirm`, Java는 `api.tools().create(...)`처럼 써요.

`TelloApi`는 Node·Python·Java 0.2.0, Go v0.3.0부터 들어 있어요(Go는 `tello.API` 타입, `tello.NewAPI`로
만들어요). 통화 생성·조회·종료·전환은 들어 있지 않아요. 통화는 `TelloClient`나
[REST 통화 API](https://docs.telloai.io/developer/rest/create-call.md)로 다뤄요.

> [!WARNING]
>
> 쓰기는 응답을 받은 다음 통화부터 바로 반영돼요. 도구·에이전트·크루를 만들거나 고치거나 지우면 저장, 배포,
> 운영 반영까지 한 번에 해요. `callDrafts.confirm`은 실제로 전화를 걸고 요금이 나가요.

## 클라이언트 만들기

키는 WebSocket과 같은 [서버용 키](https://docs.telloai.io/developer/server-keys.md)(`TELLO_API_KEY`)를 써요. 주소는 `TELLO_API_URL`,
없으면 `https://api.telloai.io/v1`이에요. `https` 주소만 받아요.

```python Python theme={null}
import asyncio
from tello import TelloApi

async def main():
    api = TelloApi()  # TELLO_API_KEY 를 읽어요
    tool = await api.tools.create(
        {"type": "endCall", "name": "통화 종료", "functionName": "end_call"},
        idempotency_key="create-end-call-1",
    )
    print(tool["id"], tool["revision"])

asyncio.run(main())
```

```typescript Node theme={null}
import { TelloApi } from "@tello-ai/sdk";

const api = new TelloApi(); // TELLO_API_KEY 를 읽어요
const tool = await api.tools.create(
  { type: "endCall", name: "통화 종료", functionName: "end_call" },
  { idempotencyKey: "create-end-call-1" },
);
console.log(tool.id, tool.revision);
```

```go Go theme={null}
api, err := tello.NewAPI("") // 빈 키면 TELLO_API_KEY 를 읽어요
if err != nil {
	log.Fatal(err)
}
tool, err := api.Tools.Create(ctx,
	tello.Object{"type": "endCall", "name": "통화 종료", "functionName": "end_call"},
	tello.WithIdempotencyKey("create-end-call-1"))
```

```java Java theme={null}
TelloApi api = new TelloApi(); // TELLO_API_KEY 를 읽어요
JsonObject body = new JsonObject();
body.addProperty("type", "endCall");
body.addProperty("name", "통화 종료");
body.addProperty("functionName", "end_call");
JsonObject tool = api.tools().create(body, "create-end-call-1").join();
```

응답은 언어의 범용 JSON 객체(Python `dict`, Node 객체, Go `tello.Object`, Java `JsonObject`)로
와요. 문서에 아직 없는 칸도 그대로 남아요. 삭제는 값을 돌려주지 않아요.

| 항목 | 내용 |
| - | - |
| 응답 대기 | 조회(`list`·`get`)는 30초, 쓰기(만들기·고치기·지우기, 크루 생성, 통화 초안)는 120초예요. 클라이언트를 만들 때 바꿀 수 있어요 |
| 재시도 | 자동으로 다시 보내지 않아요. 다시 보낼지는 멱등 키로 여러분이 정해요 |
| 멱등 키 | 넣었을 때만 보내요. `callDrafts.confirm`은 키가 꼭 필요해서, 넣지 않으면 SDK가 만들어 보내요. 1\~255자 출력 가능한 ASCII, 쉼표 없음이에요 |

## 목표로 크루 만들기

`generate`는 작업을 시작하고 바로 돌려줘요. `generateAndWait`는 작업이 끝날 때까지 2초마다 조회해요
(기본 최대 10분). 실패한 작업은 오류가 아니라 `status: "failed"`인 작업으로 와요.

```typescript Node theme={null}
const job = await api.crews.generateAndWait({
  goal: "치과 예약 고객에게 전화해 내일 예약을 확인한다",
});
if (job.status === "succeeded") console.log(job.crew?.id);
```

* 기다리는 시간이 다 돼도 작업이 진행 중이면 시간 초과 오류가 나요(Node `CrewGenerationTimeoutError`,
  Go `*tello.CrewGenerationTimeoutError`, Java `CrewGenerationTimeoutException`, Python `TimeoutError`).
  작업은 계속되니 `crewGenerations.get`으로 이어서 보세요.
* 다른 목표로 만드는 작업이 진행 중이면 `crew_generation_in_progress` 오류가 오고, `data.id`에 그
  작업 id가 있어요.

## 통화 초안

```python Python theme={null}
draft = await api.call_drafts.create({
    "agentId": "12",
    "to": "+821012345678",
    "instructions": "내일 오후 2시 예약을 확인해 주세요.",
})
if draft["status"] == "pendingConfirmation":
    print(draft["preview"]["summary"])
    call = await api.call_drafts.confirm(draft["id"])  # 실제 발신
```

* 초안의 `status`(`pendingConfirmation`·`needsClarification`·`refused`·`confirmed`)는 모두 성공 응답이에요.
  시나리오가 이미 준비된 에이전트는 `create`에서 바로 걸고 `confirmed`와 `callId`를 돌려줘요.
* `revise`는 새 id의 초안을 돌려줘요. 앞 초안은 더 확정할 수 없어요.
* `confirm`이 실패하면 오류에 보낸 멱등 키가 실려요. 응답을 받지 못했으면 **같은 키로** 다시 확정하세요.

## 오류

| 오류 | 언제 | 칸 |
| - | - | - |
| `TelloApiError` (Go `*tello.APIError`, Java `TelloApiException`) | 서버가 오류로 답했거나, 문서에 없는 응답이 왔어요 | `status`, `code`(REST 문서의 `error` 값 그대로, 예: `tool_not_found`), `message`, `data`, `idempotencyKey` |
| `TelloApiConnectionError` (Go `*tello.APIConnectionError`, Java `TelloApiConnectionException`) | 응답이 없어요. 연결 실패, 끊김, 시간 초과예요 | `idempotencyKey`, 원인 |

* 코드 목록과 대처는 [REST 오류](https://docs.telloai.io/developer/rest/errors.md)를 봐요. 오류 봉투가 아닌 응답은
  `code`가 `http_<상태>`, 문서와 다른 성공 응답은 `invalid_response`예요.
* **쓰기 요청의 연결 오류는 이미 반영됐을 수 있어요.** 확정은 이미 전화를 걸고 있을 수도 있어요. 목록·상세에서
  확인하기 전에는 새 키로 다시 만들지 말고, 같은 키로 다시 보내세요.
* Python의 칸 이름은 `idempotency_key`, Go는 `Status`·`Code`·`IdempotencyKey`처럼 언어 관례를 따라요.

```typescript Node theme={null}
import { TelloApiConnectionError, TelloApiError } from "@tello-ai/sdk";

try {
  const call = await api.callDrafts.confirm(draft.id!);
  console.log("calling", call.id);
} catch (error) {
  if (error instanceof TelloApiError && error.code === "draft_expired") {
    // 초안을 새로 만들어요
  } else if (error instanceof TelloApiConnectionError) {
    // 통화가 걸렸을 수 있어요. 새 키가 아니라 같은 키로 다시 보내요
    await api.callDrafts.confirm(draft.id!, { idempotencyKey: error.idempotencyKey! });
  } else {
    throw error;
  }
}
```

## 관련 문서

* [SDK 시작하기](https://docs.telloai.io/developer/sdk/quickstart.md)
* [REST 개요·인증](https://docs.telloai.io/developer/rest/overview.md)
* [REST 오류](https://docs.telloai.io/developer/rest/errors.md)
* [서버용 키](https://docs.telloai.io/developer/server-keys.md)


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