# Voice agent bundle

GEDX402 sells a conversational voice stack as one discoverable family. Agents pay USDC per route via x402 — no API keys.

**Discovery:** `GET https://gedx402.com/v1/models?bundle=voice` — five routes tagged `voice-agent`.

| Step | Route | Shard | Method |
| --- | --- | --- | --- |
| **Session (hero)** | `/v1/voice/sessions` | media | `POST` |
| Stream ASR | `/v1/asr/flux` | media | `GET` WebSocket |
| End-of-turn | `/v1/asr/smart-turn-v2` | media | `POST` |
| Agent reply | `/v1/chat/fast` | chat | `POST` |
| Speech out | `/v1/tts/aura-2-en` | media | `POST` |
| Alt TTS | `/v1/tts/aura-1` | media | `POST` |

Origins: `media.gedx402.com`, `chat.gedx402.com`. Each route returns `402` with x402 payment instructions until settled — except bundle routes when a valid `session_token` from `/v1/voice/sessions` has remaining credits.

**Starter route:** `POST https://media.gedx402.com/v1/voice/sessions` (`starter:true` in agents.json).

---

## Prepaid session (Slice C)

```mermaid
sequenceDiagram
  participant Agent
  participant Session as POST /v1/voice/sessions
  participant Flux as GET /v1/asr/flux
  participant Turn as POST /v1/asr/smart-turn-v2
  participant Chat as POST /v1/chat/fast
  participant TTS as POST /v1/tts/aura-2-en

  Agent->>Session: x402 payment + budget
  Session-->>Agent: session_id, session_token, credits
  Agent->>Flux: session_token (no 402 while flux seconds remain)
  Agent->>Turn: X-Voice-Session-Token
  Agent->>Chat: X-Voice-Session-Token
  Agent->>TTS: X-Voice-Session-Token
```

```http
POST https://media.gedx402.com/v1/voice/sessions
Content-Type: application/json

{
  "budget": {
    "duration_minutes": 5,
    "max_turns": 30
  }
}
```

One x402 payment covers prepaid Flux streaming seconds plus smart-turn, chat/fast, and TTS turn credits. Send `session_token` on later bundle calls:

```http
X-Voice-Session-Token: <session_token>
```

For Flux WebSocket, pass `session_token` as a query param (`?session_token=…`) or header. No `402` until the relevant credit pool is exhausted — then pay per-route or open a new session.

---

## Integration flow

```mermaid
sequenceDiagram
  participant User
  participant Agent
  participant Flux as GET /v1/asr/flux
  participant Turn as POST /v1/asr/smart-turn-v2
  participant Chat as POST /v1/chat/fast
  participant TTS as POST /v1/tts/aura-2-en

  User->>Agent: speaks (mic PCM)
  Agent->>Flux: WebSocket Upgrade + PCM chunks
  Flux-->>Agent: partial transcripts / turn events
  Agent->>Turn: audio chunk (base64)
  Turn-->>Agent: end_of_turn signal
  Agent->>Chat: messages[] with user transcript
  Chat-->>Agent: assistant text
  Agent->>TTS: reply text
  TTS-->>Agent: audio bytes
  Agent->>User: play audio
```

### 1. Flux streaming ASR (WebSocket)

**Endpoint:** `wss://media.gedx402.com/v1/asr/flux?encoding=linear16&sample_rate=16000`

1. Pay the route (x402 `GET` quote on the same URL with payment headers, or settle via your x402 client).
2. Open WebSocket with `Upgrade` on `GET /v1/asr/flux`.
3. Required query params:
   - `encoding=linear16` (PCM16 only)
   - `sample_rate` — Hz as digits, e.g. `16000`
4. Stream raw PCM frames on the socket; receive JSON turn events (e.g. `SpeechStarted`, partial/final transcripts).

`POST /v1/asr/flux` returns `405 websocket_required`.

### 2. Smart Turn v2 (end-of-turn)

When Flux indicates speech activity, POST a recent audio window to confirm the user finished speaking:

```http
POST https://media.gedx402.com/v1/asr/smart-turn-v2
Content-Type: application/json

{ "audio": "<base64 PCM or encoded clip>" }
```

Use the response to gate when you call the chat model (avoid cutting off mid-utterance).

### 3. Chat reply (fast tier)

```http
POST https://chat.gedx402.com/v1/chat/fast
Content-Type: application/json

{
  "messages": [
    { "role": "system", "content": "You are a concise voice assistant." },
    { "role": "user", "content": "<final transcript from Flux>" }
  ]
}
```

`/v1/chat/fast` is the low-latency tier suited to voice loops.

### 4. TTS (Aura)

```http
POST https://media.gedx402.com/v1/tts/aura-2-en
Content-Type: application/json

{ "text": "<assistant reply>" }
```

Returns JSON: `audio` (base64 MP3) and `content_type` (`audio/mpeg`). Optional `speaker` picks the voice (see the route's input schema). Use `aura-1` for an alternate Deepgram Aura voice profile.

---

## Pricing

Each route quotes one **USDC wire settlement** on Base. See `GET /v1/models?bundle=voice` for per-leg quotes.

**Prepaid session:** `POST /v1/voice/sessions` — **$28.11 USDC wire settlement** at default budget caps (`duration_minutes: 5`, `max_turns: 30`); scales with budget.

---

## Agent discovery

- Hub catalog: `GET /v1/models?bundle=voice`
- OpenAPI per shard: `https://media.gedx402.com/openapi.json`
- x402scan tags: `voice-agent`, `asr`, `tts`, `chat`
