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

# Migrating From Deepgram Flux

This guide covers migrating from Deepgram's Turn-based Audio (Flux) API.

Both Cartesia and Deepgram Flux emit turn-based events over a WebSocket, so migrating to Ink is mostly a matter of renaming fields and updating a few connection parameters.

<Card horizontal title="All migration guides" icon="arrow-left-from-arc" href="/use-the-api/stt/migrations" />

This guide contains both bare API descriptions and SDK code. To install the SDK:

<CodeGroup>
  ```bash Python theme={null}
  pip install cartesia
  ```

  ```bash TypeScript theme={null}
  npm i @cartesia/cartesia-js
  ```
</CodeGroup>

<Info>
  If you're already using the Cartesia SDK, upgrade to version `>=3.2.0`
</Info>

<Note>
  Ink 2 only supports English right now.\
  We expect to add more languages in the coming months.
</Note>

## Connection

Replace the Deepgram WebSocket URL and auth header with Cartesia's.

```diff theme={null}
- wss://api.deepgram.com/v2/listen?model=flux-general-en&encoding=linear16&sample_rate=16000
+ wss://api.cartesia.ai/stt/turns/websocket?model=ink-2&encoding=pcm_s16le&sample_rate=16000
```

```diff theme={null}
- Authorization: Token <DEEPGRAM_API_KEY>
+ Authorization: Bearer <CARTESIA_API_KEY>
+ Cartesia-Version: 2026-03-01
```

In browsers, WebSockets do not support request headers. Instead, pass the API version as the `cartesia_version` query param and use a short-lived [access token](/get-started/authenticate-your-client-applications) using the `access_token` query param instead of an API key.

Connect to the turn-detection WebSocket with the Cartesia SDK:

<CodeGroup>
  ```python Python (Async) theme={null}
  import os
  from cartesia import AsyncCartesia

  client = AsyncCartesia(api_key=os.getenv("CARTESIA_API_KEY"))

  async with client.stt.auto_finalize.websocket(
      model="ink-2", encoding="pcm_s16le", sample_rate=16000
  ) as connection:
      ...
  ```

  ```python Python theme={null}
  import os
  from cartesia import Cartesia

  client = Cartesia(api_key=os.getenv("CARTESIA_API_KEY"))

  with client.stt.auto_finalize.websocket(
      model="ink-2", encoding="pcm_s16le", sample_rate=16000
  ) as connection:
      ...
  ```

  ```typescript TypeScript theme={null}
  import Cartesia from "@cartesia/cartesia-js";

  const client = new Cartesia({ apiKey: process.env.CARTESIA_API_KEY });

  const connection = client.stt.autoFinalize.websocket({
    model: "ink-2",
    encoding: "pcm_s16le",
    sample_rate: 16000,
  });
  ```

  ```typescript TypeScript (Browser) theme={null}
  // Server-side: Generate access-tokens using your API key
  import Cartesia from '@cartesia/cartesia-js';

  const client = new Cartesia({ apiKey: process.env.CARTESIA_API_KEY });

  export async function GET() {
    const { token } = await client.accessToken.create({
      grants: { stt: true, tts: false, agent: false },
      // How long the token lasts in seconds
      // Allowed values: 0–3600
      expires_in: 3600,
    });
    return Response.json({ token });
  }


  // Client-side
  // 1. Fetch an access token from your server
  // 2. Connect to Cartesia via WebSocket
  import Cartesia from "@cartesia/cartesia-js";

  async function getToken(): Promise<string> {
    const res = await fetch('/replace-with-your-server');
    const { token } = await res.json();
    return token;
  }
  const audioContext = new AudioContext();

  const client = new Cartesia({ token: await getToken() });

  const connection = client.stt.autoFinalize.websocket({
    model: "ink-2",
    encoding: "pcm_f32le",
    sample_rate: audioContext.sampleRate,
  });
  ```
</CodeGroup>

## Query parameters

| Deepgram Flux                                                         | Cartesia Ink                                                                | Notes                                                                                                  |
| --------------------------------------------------------------------- | --------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------ |
| `model=flux-general-en` <Badge color="red" size="sm">required</Badge> | `model=ink-2` <Badge color="red" size="sm">required</Badge>                 | See [STT Models](/build-with-cartesia/stt/latest) for all options.                                     |
| `encoding=linear16`                                                   | `encoding=pcm_s16le` <Badge color="red" size="sm">required</Badge>          | See [encoding](#encoding) for all options.                                                             |
| `sample_rate`                                                         | `sample_rate` <Badge color="red" size="sm">required</Badge>                 | No change.                                                                                             |
| `language_hint`                                                       | —                                                                           | Only English is supported right now. Multi-lingual support is coming soon!                             |
| —                                                                     | `cartesia_version=2026-03-01` <Badge color="red" size="sm">required</Badge> | See [API Conventions](/use-the-api/api-conventions#always-send-a-cartesia-version-header) for details. |
| `eager_eot_threshold`, `eot_threshold`, `eot_timeout_ms`              | —                                                                           | Turn detection is controlled by the model. Configuration is coming soon!                               |
| `keyterm`                                                             | —                                                                           | Coming soon!                                                                                           |
| `mip_opt_out`                                                         | —                                                                           | Controlled by your organization.                                                                       |

<Accordion title="encoding">
  | Deepgram      | Cartesia      |
  | ------------- | ------------- |
  | `linear16`    | `pcm_s16le`   |
  | `linear32`    | `pcm_s32le`   |
  | `mulaw`       | `pcm_mulaw`   |
  | `alaw`        | `pcm_alaw`    |
  | Not supported | `pcm_f16le`   |
  | Not supported | `pcm_f32le`   |
  | `opus`        | Not supported |
  | `ogg-opus`    | Not supported |
</Accordion>

## Sending audio

Both APIs accept raw PCM audio as binary WebSocket frames in the same way.

> Cartesia does not support these encodings: `opus`, `ogg-opus`

To close the session, send a JSON encoded WebSocket text frame:

```diff theme={null}
- { "type": "CloseStream" }
+ { "type": "close" }
```

Cartesia has no equivalent of Deepgram's `Configure` control message since there's no need to configure end-of-turn.

<CodeGroup>
  ```python Python (Async) theme={null}
  # Equivalent to 
  # deepgram_connection.send_media(audio_chunk)
  await connection.send_raw(audio_chunk)

  # Equivalent to
  # deepgram_connection.send_close_stream()
  await connection.send({"type": "close"})
  ```

  ```python Python theme={null}
  # Equivalent to 
  # deepgram_connection.send_media(audio_chunk)
  connection.send_raw(audio_chunk)

  # Equivalent to
  # deepgram_connection.send_close_stream()
  connection.send({"type": "close"})
  ```

  ```typescript TypeScript theme={null}
  // Equivalent to deepgramConnection.sendMedia(audioChunk)
  // @param {ArrayBufferLike} audioChunk - Note: Blob is not accepted
  connection.sendRaw(audioChunk);

  // Equivalent to
  // deepgramConnection.sendCloseStream({ type: "CloseStream" })
  connection.send({ type: "close" });
  ```
</CodeGroup>

## Event mapping

| Deepgram `type` | Cartesia `type` |
| --------------- | --------------- |
| `Connected`     | `connected`     |
| `Error`         | `error`         |
| `TurnInfo`      | See below       |

Deepgram wraps all turn events in a single `TurnInfo` message with an `event` discriminator. Cartesia emits one message type per event, with the type on the top-level `type` field.

| Deepgram `TurnInfo.event` | Cartesia `type`  | Carries `transcript`? |
| ------------------------- | ---------------- | --------------------- |
| `StartOfTurn`             | `turn.start`     | No (Deepgram: yes)    |
| `Update`                  | `turn.update`    | Yes                   |
| `EagerEndOfTurn`          | `turn.eager_end` | Yes                   |
| `TurnResumed`             | `turn.resume`    | No (Deepgram: yes)    |
| `EndOfTurn`               | `turn.end`       | Yes                   |

A Deepgram `TurnInfo` message:

```json theme={null}
{
  "type": "TurnInfo",
  "event": "EndOfTurn",
  "turn_index": 0,
  "transcript": "Hi I need to cancel my subscription please.",
  "words": [...],
  "end_of_turn_confidence": 0.7,
  "audio_window_start": 0.0,
  "audio_window_end": 1.7
}
```

Becomes a Cartesia `turn.*` event:

```json theme={null}
{
  "type": "turn.end",
  "transcript": "Hi I need to cancel my subscription please.",
  "request_id": "2ff8af53-4d38-479d-8287-58940f01c701"
}
```

Like Deepgram, the `transcript` is cumulative within a turn.

## Event handler

The branching structure of your handler is unchanged — just the message shape.

```diff theme={null}
  ws.onmessage = (message) => {
    const data = JSON.parse(message.data);
-   if (data.type !== "TurnInfo") return;
-   switch (data.event) {
-     case "StartOfTurn":    onTurnStart(); break;
-     case "Update":         onTranscriptUpdate(data.transcript); break;
-     case "EagerEndOfTurn": prepareReply(data.transcript); break;
-     case "TurnResumed":    cancelReply(); break;
-     case "EndOfTurn":      finalizeReply(data.transcript); break;
-   }
+   switch (data.type) {
+     case "turn.start":     onTurnStart(); break;
+     case "turn.update":    onTranscriptUpdate(data.transcript); break;
+     case "turn.eager_end": prepareReply(data.transcript); break;
+     case "turn.resume":    cancelReply(); break;
+     case "turn.end":       finalizeReply(data.transcript); break;
+   }
  };
```

<CodeGroup>
  ```python Python (Async) theme={null}
  import asyncio
  from cartesia.types.stt import STTAutoFinalizeWebsocketResponse

  def on_message(message: STTAutoFinalizeWebsocketResponse) -> None:
      if message.type == "turn.start":
          print("StartOfTurn")
      elif message.type == "turn.update":
          print(f"Update: {message.transcript}")
      elif message.type == "turn.eager_end":
          print(f"EagerEndOfTurn: {message.transcript}")
      elif message.type == "turn.resume":
          print("TurnResumed")
      elif message.type == "turn.end":
          print(f"EndOfTurn: {message.transcript}")
      elif message.type == "error":
          print(f"Error: {message.message}")

  # Equivalent to
  # deepgram_connection.on(EventType.MESSAGE, on_message)
  connection.on("event", on_message)

  # Equivalent to
  # asyncio.create_task(deepgram_connection.start_listening())
  recv_task = asyncio.create_task(connection.dispatch_events())
  ```

  ```python Python theme={null}
  import threading
  from cartesia.types.stt import STTAutoFinalizeWebsocketResponse

  def on_message(message: STTAutoFinalizeWebsocketResponse) -> None:
      if message.type == "turn.start":
          print("StartOfTurn")
      elif message.type == "turn.update":
          print(f"Update: {message.transcript}")
      elif message.type == "turn.eager_end":
          print(f"EagerEndOfTurn: {message.transcript}")
      elif message.type == "turn.resume":
          print("TurnResumed")
      elif message.type == "turn.end":
          print(f"EndOfTurn: {message.transcript}")
      elif message.type == "error":
          print(f"Error: {message.message}")

  # Equivalent to
  # deepgram_connection.on(EventType.MESSAGE, on_message)
  connection.on("event", on_message)

  # Equivalent to
  # threading.Thread(target=deepgram_connection.start_listening, daemon=True).start()
  threading.Thread(target=connection.dispatch_events, daemon=True).start()
  ```

  ```typescript TypeScript theme={null}
  import Cartesia from '@cartesia/cartesia-js';

  // Equivalent to
  // deepgramConnection.on("message", (message) => { ... });
  connection.on("event", (message: Cartesia.STT.AutoFinalize.STTAutoFinalizeWebsocketResponse) => {
    switch (message.type) {
      case "turn.start":
        console.log("StartOfTurn");
        break;
      case "turn.update":
        console.log(`Update: ${message.transcript}`);
        break;
      case "turn.eager_end":
        console.log(`EagerEndOfTurn: ${message.transcript}`);
        break;
      case "turn.resume":
        console.log("TurnResumed");
        break;
      case "turn.end":
        console.log(`EndOfTurn: ${message.transcript}`);
        break;
    }
  });

  // Equivalent to
  // deepgramConnection.on("error", (error) => { ... });
  connection.on("error", (error) => {
    if (error.error) {
      // Server sent error (may be a bad request or internal server error)
      console.error(`Server sent an error: ${error.error.message}`);
    } else {
      // Client error
      console.error(`Client had an error: ${error.message}`);
    }
  });
  ```
</CodeGroup>

## Example Server Messages

> Flux's transcripts are joined with spaces. Ink's are not.

| Deepgram Flux                                                                         | Cartesia Realtime STT (Auto)                                                             |
| ------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- |
| <Badge>StartOfTurn</Badge>                                                            | <Badge>turn.start</Badge>                                                                |
| <Badge color="orange">Update</Badge> `"Flux's transcripts"`                           | <Badge color="orange">turn.update</Badge> `"Flux's transcripts"`                         |
| <Badge>EagerEndOfTurn</Badge> `"Flux's transcripts"`                                  | <Badge>turn.eager\_end</Badge> `"Flux's transcripts"`                                    |
| <Badge>TurnResumed</Badge>                                                            | <Badge>turn.resume</Badge>                                                               |
| <Badge color="orange">Update</Badge> `"Flux's transcripts are joined with spaces."`   | <Badge color="orange">turn.update</Badge> `"Flux's transcripts are joined with spaces."` |
| <Badge>EagerEndOfTurn</Badge> `"Flux's transcripts are joined with spaces."`          | <Badge>turn.eager\_end</Badge> `"Flux's transcripts are joined with spaces."`            |
| <Badge color="green">EndOfTurn</Badge> `"Flux's transcripts are joined with spaces."` | <Badge color="green">turn.end</Badge> `"Flux's transcripts are joined with spaces."`     |
| <Badge>StartOfTurn</Badge>                                                            | <Badge>turn.start</Badge>                                                                |
| <Badge color="orange">Update</Badge> `"Ink's are not."`                               | <Badge color="orange">turn.update</Badge> `" Ink's are not."`                            |
| <Badge>EagerEndOfTurn</Badge> `"Ink's are not."`                                      | <Badge>turn.eager\_end</Badge> `" Ink's are not."`                                       |
| <Badge color="green">EndOfTurn</Badge> `"Ink's are not."`                             | <Badge color="green">turn.end</Badge> `" Ink's are not."`                                |

## References

<CardGroup cols={2}>
  <Card icon="code" title="API Reference" href="/api-reference/stt/turns/websocket">
    Cartesia Realtime STT (Auto)
  </Card>

  <Card icon="brackets-curly" title="Full Code Example" href="/examples/stt-auto-finalize-websocket">
    Using the Cartesia SDK
  </Card>
</CardGroup>
