# API 개요

> REST 및 GraphQL을 통해 PentAGI를 자동화합니다 — Bearer 토큰을 생성하고, CI/CD에서 flows를 시작하며, 결과를 자체 도구로 가져오고 클라이언트를 생성합니다.

웹 UI에서 수행할 수 있는 대부분의 작업을 API를 통해 이용하실 수 있습니다. CI/CD에서 [flows](https://pentagi.com/ko/docs/glossary/#flow)를 시작하거나, 결과를 자체 도구로 가져오거나, 통합 기능을 구축하세요.

| API     | 엔드포인트             | 인터랙티브 문서                     |
| ------- | ----------------- | ---------------------------- |
| GraphQL | `/api/v1/graphql` | `/api/v1/graphql/playground` |
| REST    | `/api/v1/...`     | `/api/v1/swagger/index.html` |

## [토큰 생성하기](https://pentagi.com/ko/docs/api/overview/#create-a-token)

1. 웹 UI에서 **Settings → API Tokens**를 엽니다.
2. **Create Token**을 클릭하고, 선택적으로 이름을 지정한 뒤 1분에서 3년 사이의 만료 기간을 설정합니다.
3. 토큰은 한 번만 표시되므로 즉시 복사하세요.

토큰은 사용자의 계정에 속하며 해당 역할의 권한을 상속받습니다. 사용자, 역할 및 API 토큰, flow 템플릿, 즐겨찾기 및 설정은 로그인된 브라우저 세션에서만 관리됩니다. 토큰은 REST `/users`, `/roles` 및 `/tokens` 라우트에서 403 오류를 받고, 해당 GraphQL 작업에서도 오류가 발생합니다.

## [API 호출하기](https://pentagi.com/ko/docs/api/overview/#call-the-api)

```bash
curl -X POST https://your-pentagi-host:8443/api/v1/graphql \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"query": "{ flows { id title status } }"}'

curl https://your-pentagi-host:8443/api/v1/flows/ \
  -H "Authorization: Bearer YOUR_API_TOKEN"
```

GraphQL 뮤테이션으로 flow를 시작합니다:

```graphql
mutation CreateFlow {
  createFlow(modelProvider: "openai", input: "Test the security of https://example.com") {
    id
    title
    status
    createdAt
  }
}
```

## [클라이언트 생성하기](https://pentagi.com/ko/docs/api/overview/#generate-a-client)

* **GraphQL** — 스키마는 리포지토리의 `backend/pkg/graph/schema.graphqls`에 있습니다. GraphQL Code Generator, genqlient 또는 Apollo를 사용하세요.
* **REST** — OpenAPI 명세는 `/api/v1/swagger/doc.json`에서 제공됩니다:

```bash
openapi-generator-cli generate \
  -i https://your-pentagi-host:8443/api/v1/swagger/doc.json \
  -g python \
  -o ./pentagi-client
```