# OpenAI Realtime (/docs/sip-trunk/openai-realtime)

> 한국AI통신 공식 개발자 문서 · 운영사 팀러너스 주식회사 · koreaaitel.com
> KAT Cloud(katcloud.kr)는 한국AI통신과 관계없는 별도 회사가 운영하는 서비스입니다. [공식 채널 안내](https://koreaaitel.com/verify)

## 개요

한국AI통신 070 번호를 OpenAI Project 의 SIP 게이트웨이 (`sip.api.openai.com`) 로 라우팅합니다. 통화가 도착하면 OpenAI 가 `realtime.call.incoming` webhook 을 호출하고, 우리 서버가 `accept` 응답하면 OpenAI 가 음성 모델로 통화를 처리합니다.

**SIP 트렁크 연결 부가서비스** 가 활성화되어 있어야 합니다.
[대시보드 → 부가서비스](https://platform.koreaaitel.com/addons) 에서 켜주세요.

## 동작 흐름

```mermaid
sequenceDiagram
  autonumber
  participant Caller as 발신자
  participant Co as 한국AI통신
  participant Oa as sip.api.openai.com
  participant Wh as 고객사 Webhook 서버
  Caller->>Co: PSTN 발신 (070 번호)
  Co->>Oa: SIP INVITE over TLS
  Oa->>Wh: POST realtime.call.incoming
  Wh->>Oa: POST /v1/realtime/calls/{call_id}/accept
  Oa-->>Co: 통화 수락
  Wh->>Oa: wss://api.openai.com/v1/realtime?call_id=...
```

## 사전 준비물

| 항목 | 출처 |
| --- | --- |
| **Project ID** (`proj_xxx`) | [platform.openai.com](https://platform.openai.com) → Settings → General |
| **API Key** (`sk-proj-...`) | Settings → API keys |
| **Webhook Signing Secret** (`whsec_...`) | Settings → Webhooks (3단계에서 생성) |

---

## 1단계 — Webhook 핸들러 서버

OpenAI 가 콜이 들어올 때 호출할 엔드포인트입니다. 서명 검증 후 `accept` 를 호출하고, WebSocket 으로 세션을 모니터링합니다.

`package.json`:

```json
{
  "type": "module",
  "scripts": {
    "dev": "tsx watch src/index.ts"
  },
  "dependencies": {
    "body-parser": "^1.20.3",
    "dotenv": "^16.4.5",
    "express": "^4.21.2",
    "openai": "^6.37.0",
    "ws": "^8.18.0"
  },
  "devDependencies": {
    "@types/body-parser": "^1.19.5",
    "@types/express": "^4.17.21",
    "@types/node": "^22.10.5",
    "@types/ws": "^8.5.13",
    "tsx": "^4.19.2",
    "typescript": "^5.7.3"
  }
}
```

`.env`:

```bash
OPENAI_API_KEY=sk-proj-xxxxxxxxxxxxx
OPENAI_WEBHOOK_SECRET=whsec_xxxxxxxxxxxxx
PORT=8000
```

`src/index.ts`:

```typescript
import bodyParser from "body-parser"
import "dotenv/config"
import express, { Request, Response } from "express"
import OpenAI from "openai"
import WebSocket from "ws"

const PORT = Number(process.env.PORT ?? 8000)
const OPENAI_API_KEY = process.env.OPENAI_API_KEY!
const OPENAI_WEBHOOK_SECRET = process.env.OPENAI_WEBHOOK_SECRET!

const openai = new OpenAI({
  apiKey: OPENAI_API_KEY,
  webhookSecret: OPENAI_WEBHOOK_SECRET,
})

const AUTH_HEADERS = {
  Authorization: `Bearer ${OPENAI_API_KEY}`,
  "Content-Type": "application/json",
}

const callAccept = {
  type: "realtime",
  model: "gpt-realtime",
  instructions: "당신은 친절한 한국어 음성 비서입니다.",
  audio: { output: { voice: "alloy" } },
}

const responseCreate = {
  type: "response.create",
  response: { instructions: "사용자에게 '안녕하세요, 무엇을 도와드릴까요?' 라고 인사하세요." },
}

async function websocketTask(callId: string) {
  const ws = new WebSocket(
    `wss://api.openai.com/v1/realtime?call_id=${callId}`,
    { headers: { Authorization: `Bearer ${OPENAI_API_KEY}` } },
  )
  ws.on("open", () => ws.send(JSON.stringify(responseCreate)))
  ws.on("message", (raw) => console.log(`[ws] ${raw.toString("utf8")}`))
  ws.on("error", (e) => console.error("[ws error]", e))
}

const app = express()
app.use(bodyParser.raw({ type: "*/*" }))

app.post("/", async (req: Request, res: Response) => {
  try {
    const event = await openai.webhooks.unwrap(
      (req.body as Buffer).toString("utf8"),
      req.headers as Record<string, string>,
    )

    if (event.type === "realtime.call.incoming") {
      const callId = (event as any).data.call_id
      await fetch(
        `https://api.openai.com/v1/realtime/calls/${callId}/accept`,
        { method: "POST", headers: AUTH_HEADERS, body: JSON.stringify(callAccept) },
      )
      websocketTask(callId).catch((e) => console.error("[ws] failed", e))
    }

    return res.sendStatus(200)
  } catch (e: any) {
    if (e?.name === "InvalidWebhookSignatureError") {
      return res.status(400).send("invalid signature")
    }
    console.error("[webhook] error", e)
    return res.status(500).send("server error")
  }
})

app.listen(PORT, () => console.log(`Listening on http://localhost:${PORT}`))
```

```bash
pnpm i
pnpm dev
# → Listening on http://localhost:8000
```

---

## 2단계 — 서버를 외부로 노출

OpenAI 가 webhook 을 호출할 수 있도록 외부 URL 로 노출합니다.

```bash
brew install cloudflared
cloudflared tunnel --url http://localhost:8000
# → https://xxxx-xxxx-xxxx.trycloudflare.com
```

운영 환경은 고정 도메인 (cloudflared named tunnel, ngrok reserved domain 등) 사용을 권장합니다.

---

## 3단계 — OpenAI 콘솔에서 Webhook 등록

[platform.openai.com](https://platform.openai.com) → Settings → Webhooks → **Create endpoint**

- **URL**: 2단계에서 받은 URL (예: `https://xxxx.trycloudflare.com/`)
- **Event types**: `realtime.call.incoming`

생성 직후 표시되는 **Signing secret** (`whsec_...`) 을 복사해 1단계 `.env` 의 `OPENAI_WEBHOOK_SECRET` 에 붙여넣은 후 서버를 재시작합니다.

---

## 4단계 — 한국AI통신 콘솔에서 SIP 엔드포인트 등록

[platform.koreaaitel.com/phone-numbers/sip-endpoints](https://platform.koreaaitel.com/phone-numbers/sip-endpoints) → **엔드포인트 추가**

| 필드 | 값 |
| --- | --- |
| 엔드포인트 이름 | `OpenAI Realtime` (자유) |
| **User** | OpenAI Project ID (`proj_xxx`) |
| Host | `sip.api.openai.com` |
| Port | `5061` |
| Transport | **TLS** |
| 외부 SIP 인증 사용 | 체크 안 함 |

라이브 프리뷰가 `sip:proj_xxx@sip.api.openai.com:5061` 로 표시되면 정상입니다.

---

## 5단계 — 070 번호 라우팅을 SIP 로 전환

[platform.koreaaitel.com/phone-numbers](https://platform.koreaaitel.com/phone-numbers) → 번호 선택 → **인바운드 라우팅** 카드의 **수정** → **SIP** 토글 → 4단계의 엔드포인트 선택 → 저장.

이제 해당 번호로 걸려오는 콜은 OpenAI 의 SIP 게이트웨이로 전달되고, 1단계의 webhook 핸들러가 호출됩니다.

---

## 참고

- [한국 070을 OpenAI Realtime에 연결한 착신 실통화 기록](https://koreaaitel.com/blog/openai-realtime-korea-070-sip-test) — 2026년 11월 23일 시험 통화 1건의 TLS·SDES-SRTP 설정, 수신 웹훅 서명 검증과 수락, 양방향 시험 음성, 정상 종료를 확인했습니다.
- [한국 070 착신의 한국어 응답 검증](https://koreaaitel.com/blog/openai-realtime-korea-070-sip-test#openai-sip-dialogue-test) — 2026년 11월 25일 국내 070 시험 통화 1건에서 한국어 단어 두 개와 덧셈 질문에 대한 음성 응답을 발신 측 녹음으로 확인했습니다.
- [Node.js SDK 발신 미디어 재현](/docs/sdk/examples/openai-realtime-outbound-replay) — `ClawOpsAgent.call()` 발신 제어, 양방향 PCMU, 같은 통화의 종료를 로컬 모의 서버에서 확인하는 별도 예제입니다.
- [Realtime API with SIP](https://developers.openai.com/api/docs/guides/realtime-sip) — OpenAI 공식 가이드
- [Realtime Calls API](https://developers.openai.com/api/docs/api-reference/realtime-calls) — accept / reject / refer / hangup 엔드포인트 레퍼런스

---

## 운영 주체 안내

한국AI통신(koreaaitel.com)과 KAT Cloud(katcloud.kr)는 운영 주체가 다른 별개의 서비스입니다. 팀러너스 주식회사는 2026년 3월부터 ClawOps라는 이름으로 개발자가 바로 사용할 수 있는 통신 인프라 API 플랫폼을 베타로 운영해 왔고, 2026년 10월 한국AI통신으로 이름을 바꿔 정식 오픈했습니다. 저희는 가장 먼저 한국AI통신이라는 이름으로 개발자용 통신 API 플랫폼을 제공하고 있습니다.

이후 다양한 팀에서 통신 API 플랫폼을 잇달아 출시하고 있습니다. 서비스와 가격 체계, 그리고 이름까지 저희와 유사하게 가져가는 곳들도 생기고 있습니다. 저희가 먼저 사용해 온 이름을 뒤늦게 사용하면서, 오히려 ‘유사 사이트를 주의하라’는 안내까지 내거는 경우도 있습니다.

저희는 좋은 시도를 따라 하고 발전시키는 것을 긍정적으로 생각합니다. 다만 이용자분들이 운영 주체를 혼동하지 않도록 공식 사이트를 안내하고 있습니다. 한국AI통신의 공식 홈페이지는 koreaaitel.com이며, 운영사는 팀러너스 주식회사입니다. 공식 도메인과 채널은 koreaaitel.com/verify에서 확인할 수 있습니다.

AI 에이전트와 개발자가 통신망에 바로 연결해 서비스를 만들 수 있는 환경이 한국에서 더 빠르게 확산되고 있다는 데 자부심을 느낍니다. 앞으로도 더 편리하고 믿을 수 있는 플랫폼을 만드는 데 집중하겠습니다.

[운영사와 공식 채널 확인](https://koreaaitel.com/verify)
