Install and configure the official Gladia SDKs (@gladiaio/sdk for JS/TS, gladiaio-sdk for Python). Use when the user asks about SDK setup, client initialization, API key configuration, choosing between JS and Python, browser usage, retry/timeout settings, error handling, or SDK vs raw API decisions. The SDK is the recommended default for all Gladia integrations.
---
name: gladia-sdk-integration
description: Install and configure the official Gladia SDKs (@gladiaio/sdk for JS/TS, gladiaio-sdk for Python). Use when the user asks about SDK setup, client initialization, API key configuration, choosing between JS and Python, browser usage, retry/timeout settings, error handling, or SDK vs raw API decisions. The SDK is the recommended default for all Gladia integrations.
license: MIT
---
# SDK Integration
Official SDKs for integrating Gladia's speech-to-text API. Both SDKs share the same design and are generated from the Gladia OpenAPI schema.
> **The SDK is the default for all Gladia integrations.** Always use the SDK unless there is a specific, documented reason not to (see decision guide below).
## When to Use
- User asks about installing, configuring, or initializing the Gladia SDK
- Setting up API key, region, retry, timeout, or WebSocket configuration
- Questions about SDK architecture, client methods, or type exports
- Choosing between JS/TS and Python SDK, or between SDK and raw API
- Browser-based integration, proxy setup, or bundle format questions
- Error handling patterns for Gladia API responses
**When NOT to use:** If the user is asking about a specific transcription use case (pre-recorded files or live streaming), start with the relevant use-case skill ([gladia-pre-recorded-transcription](../gladia-pre-recorded-transcription/SKILL.md) or [gladia-live-transcription](../gladia-live-transcription/SKILL.md)) instead — those skills reference back here for setup details.
## When to Use SDK vs Raw API
| Scenario | Approach |
| ---------------------------------------- | ------------------------------------------------------------------------------------------------------------- |
| Any JS/TS or Python project | **SDK** — always |
| Browser app | **SDK** — JS SDK supports ESM/IIFE bundles |
| Need custom HTTP client or middleware | SDK first; use `httpHeaders` / `httpTimeout` config. Fall back to raw REST only if SDK config is insufficient |
| Language without an SDK (Go, Java, etc.) | Raw REST/WebSocket (SDK unavailable) |
| User explicitly requests raw calls | Raw REST/WebSocket |
| CI script or one-off curl test | Raw REST is acceptable |
| Terminal one-off with gladia-cli on PATH | **CLI** — see [gladia-using-cli](../gladia-using-cli/SKILL.md) |
When in doubt, use the SDK.
## References
Consult these resources as needed:
- ./references/sdk-versions.md -- Current SDK versions (auto-synced by CI)
- ./references/client-config.md -- Full client configuration reference (all options, defaults, timeouts)
- ./references/javascript.md -- JS/TS-specific patterns (browser, proxy, File/Blob, Node requirements)
- ./references/python.md -- Python-specific patterns (sync/async, typed requests, httpx/websockets)
- ../gladia-using-cli/SKILL.md -- Terminal transcription with gladia-cli; CLI vs SDK routing
- ../gladia-pre-recorded-transcription/SKILL.md -- Pre-recorded transcription options, response structure, and audio intelligence config
- ../gladia-live-transcription/SKILL.md -- Live session config, audio streaming, and WebSocket event handling
- ../gladia-troubleshooting/SKILL.md -- Common errors, gotchas, and verification checklist
## Installation
### JavaScript / TypeScript
```bash
npm install @gladiaio/sdk
# or
bun add @gladiaio/sdk
# or
yarn add @gladiaio/sdk
```
Requires Node.js 20+ or Bun. Also works in browsers via ESM/IIFE bundles.
### Python
```bash
pip install gladiaio-sdk
# or
uv add gladiaio-sdk
```
Requires Python 3.10+.
## Client Initialization
### JavaScript/TypeScript
```typescript
import { GladiaClient } from "@gladiaio/sdk";
const client = new GladiaClient({
apiKey: "your-api-key", // or set GLADIA_API_KEY env var
region: "eu-west", // or set GLADIA_REGION (eu-west | us-west)
});
```
### Python
```python
from gladiaio_sdk import GladiaClient
client = GladiaClient(
api_key="your-api-key", # or set GLADIA_API_KEY env var
region="eu-west", # or set GLADIA_REGION
)
```
### Environment Variables
| Variable | Purpose | Default |
| ---------------- | -------------------------- | ----------------------- |
| `GLADIA_API_KEY` | API key for authentication | — |
| `GLADIA_API_URL` | Base API URL | `https://api.gladia.io` |
| `GLADIA_REGION` | Datacenter region | — |
## Client Architecture
```
GladiaClient
├── preRecorded() → PreRecordedV2Client (JS)
│ prerecorded() → PreRecordedV2Client (Python)
│
├── liveV2() → LiveV2Client (JS)
│ live() → LiveV2Client (Python)
│
└── (Python only)
├── prerecorded_async() → AsyncPreRecordedV2Client
└── live_async() → AsyncLiveV2Client
```
### Pre-Recorded Client Methods
| Method | Purpose |
| ------------------------------------ | ---------------------------------- |
| `transcribe(audio, options)` | High-level: upload + create + poll |
| `uploadFile(audio)` | Upload local file to `/v2/upload` |
| `create(options)` | Create transcription job |
| `createAndPoll(options)` | Create + poll until done |
| `poll(jobId, { interval, timeout })` | Poll until complete |
| `get(jobId)` | Get job status/results |
| `delete(jobId)` | Delete job and data |
| `getFile(jobId)` | Download original audio |
### Live Client Methods
| Method | Purpose |
| ----------------------- | ------------------------------------ |
| `startSession(options)` | Init session → returns LiveV2Session |
| `get(sessionId)` | Get completed session results |
| `delete(sessionId)` | Delete session and data |
| `getFile(sessionId)` | Download session audio |
### Live Session Methods
| Method | Purpose |
| ------------------ | -------------------------------------- |
| `sendAudio(chunk)` | Stream audio bytes to the session |
| `stopRecording()` | End recording, trigger post-processing |
| `endSession()` | Force close without post-processing |
| `getSessionId()` | Await session ID (async) |
## Configuration Options
Key client options: `apiKey`, `apiUrl`, `region`, `httpTimeout`, `httpRetry`, `wsRetry`, `wsTimeout`, `prerecordedTimeouts`, `liveTimeouts`.
For the full config reference with all options and defaults, see [./references/client-config.md](./references/client-config.md).
## Audio Input Types
| Input | JS/TS | Python |
| ------------------------------- | :-------: | :----: |
| Local file path (string) | Node only | Yes |
| `Path` object | — | Yes |
| HTTP(S) URL | Yes | Yes |
| `File` / `Blob` | Browser | — |
| Binary file object (`BinaryIO`) | — | Yes |
URLs are passed directly as `audio_url` without upload. Local files are automatically uploaded via `/v2/upload`.
## Error Handling
### JavaScript/TypeScript
```typescript
try {
const result = await client.preRecorded().transcribe("./audio.mp3", options);
} catch (error) {
if (error.message.includes("401")) {
console.error("Invalid API key");
} else if (error.message.includes("timeout")) {
console.error("Request timed out");
}
}
```
### Python
```python
from gladiaio_sdk import GladiaClient
try:
result = client.prerecorded().transcribe("audio.mp3", options)
except Exception as e:
print(f"Error: {e}")
```
Python exports `HttpError` and `TimeoutError` for specific error handling.
## Key Differences Between JS and Python
| Aspect | JavaScript/TypeScript | Python |
| --------------- | ------------------------------------------- | ---------------------------------------- |
| Async model | Promise-based (async only) | Sync + async (separate clients) |
| Naming | camelCase (`preRecorded`, `sendAudio`) | snake_case (`prerecorded`, `send_audio`) |
| Browser support | Yes (ESM, CJS, IIFE) | No (server only) |
| Runtime | Node 20+, Bun, browsers | Python 3.10+ |
| Dependencies | 0 runtime deps (optional `ws` for Node <22) | httpx, websockets, pyee |
| Options format | Plain objects (snake_case keys) | Dataclasses or dicts |
| Untyped API | `transcribeUntyped()`, `createUntyped()` | Dict accepted on most methods |
## Type Exports
Both SDKs export all request/response types from the main package:
```typescript
import type {
LiveV2InitRequest,
LiveV2WebSocketMessage,
PreRecordedV2Response,
PreRecordedV2TranscriptionOptions,
} from "@gladiaio/sdk";
```
```python
from gladiaio_sdk import (
LiveV2InitRequest,
LiveV2WebSocketMessage,
LiveV2LanguageConfig,
LiveV2MessagesConfig,
PreRecordedV2Response,
)
```
## Common Mistakes
- **Wrong sub-client method name between JS and Python**: JS uses `client.preRecorded()` and `client.liveV2()`; Python uses `client.prerecorded()` and `client.live()`. Mixing the naming conventions causes "is not a function" / `AttributeError` at runtime.
- **Forgetting `await` in JavaScript**: every JS SDK method returns a Promise. Omitting `await` on `transcribe()`, `startSession()`, etc. lets the operation run silently in the background with no result or error surfaced to your code.
- **API key exposed in browser-side code**: never embed the API key directly in front-end JavaScript — it becomes publicly readable. Use a backend proxy that forwards requests with the key server-side. See [./references/javascript.md](./references/javascript.md) for the proxy pattern.
- **Node.js < 22 without the `ws` peer dependency**: the JS SDK requires the `ws` package for WebSocket on Node < 22, which lacks a native WebSocket. Without it, live sessions fail silently. Fix: `npm install ws`.
- **Python async client in sync context**: `client.live_async()` and `client.prerecorded_async()` cannot be called from synchronous code — they require an active event loop. Use the sync client (`client.live()`, `client.prerecorded()`) unless you are inside an `async def`.
## Further Reading
- [SDK integration guide](https://docs.gladia.io/chapters/integrations/sdk)
- [JS SDK on npm](https://www.npmjs.com/package/@gladiaio/sdk)
- [Python SDK on PyPI](https://pypi.org/project/gladiaio-sdk/)
- [SDK source code](https://github.com/gladiaio/sdk)
- [Code samples](https://github.com/gladiaio/gladia-samples)
don't have the plugin yet? install it then click "run inline in claude" again.
Official SDKs for integrating Gladia's speech-to-text API. Both SDKs share the same design and are generated from the Gladia OpenAPI schema. The SDK is the default for all Gladia integrations. Always use the SDK unless there is a specific, documented reason not to.
Use this skill when a user asks about installing, configuring, or initializing the Gladia SDK (JS/TS or Python). This includes API key setup, region selection, retry/timeout configuration, WebSocket settings, error handling patterns, choosing between SDK and raw API, or browser-based integration questions. The SDK is the recommended default for all Gladia integrations. do not use this skill if the user is asking about a specific transcription use case (pre-recorded files or live streaming) - start with the relevant use-case skill instead (gladia-pre-recorded-transcription or gladia-live-transcription), which reference back here for setup details.
apiKey parameter or set environment variable GLADIA_API_KEY. if missing, client initialization fails with 401 error.region parameter or GLADIA_REGION env var. valid values: eu-west (default), us-west. affects api endpoint and latency.https://api.gladia.io (default, configurable via GLADIA_API_URL or apiUrl parameter). requires outbound https and websocket connectivity.@gladiaio/sdk package.gladiaio-sdk package.Input: user's project language and runtime.
Action: install appropriate sdk package.
JS/TypeScript (requires node.js 20+, bun, or browser support):
npm install @gladiaio/sdk
Python (requires python 3.10+):
pip install gladiaio-sdk
Output: package installed in node_modules/ or site-packages/. verify with npm list @gladiaio/sdk or pip show gladiaio-sdk.
Input: user's gladia console credentials.
Action: retrieve api key from https://console.gladia.io and store securely.
Output: api key string (format: alphanumeric, ~40 chars). store in environment variable GLADIA_API_KEY or pass directly to client constructor in step 3.
Note: never embed api key in browser-side code; use backend proxy (see decision points).
Input: api key, optional region, optional timeout/retry config.
JS/TypeScript:
import { GladiaClient } from "@gladiaio/sdk";
const client = new GladiaClient({
apiKey: process.env.GLADIA_API_KEY, // or hardcoded for non-public code
region: "eu-west", // optional, defaults to eu-west
httpTimeout: 30000, // optional, ms
httpRetry: { maxRetries: 3, backoff: "exponential" }, // optional
wsTimeout: 60000, // optional, for live sessions
wsRetry: { maxRetries: 5 }, // optional
});
Python:
from gladiaio_sdk import GladiaClient
client = GladiaClient(
api_key=os.getenv("GLADIA_API_KEY"),
region="eu-west",
http_timeout=30000,
http_retry={"max_retries": 3, "backoff": "exponential"},
ws_timeout=60000,
ws_retry={"max_retries": 5},
)
Output: client object ready to call sub-clients (preRecorded() / prerecorded(), liveV2() / live(), or async variants in python).
Common Issues: if api key is invalid or missing, client construction succeeds but the first api call returns 401 error.
Input: client object from step 3, use case type (pre-recorded or live).
Action: call appropriate sub-client method.
JS/TypeScript:
client.preRecorded()client.liveV2()Python (sync):
client.prerecorded()client.live()Python (async):
client.prerecorded_async()client.live_async()Output: sub-client object (PreRecordedV2Client, LiveV2Client, or async variants). proceed to relevant use-case skill for transcription details.
Input: audio source (local file, url, blob/file, or stream), transcription options (language, model, features).
Action: prepare audio input and options dict/object. for pre-recorded: transcribe(audio, options) auto-uploads local files. for live: startSession(options) sets session config.
Output: audio reference and options ready to pass to sub-client methods. (detailed procedure for this step is in gladia-pre-recorded-transcription or gladia-live-transcription).
Input: potential api/network errors during transcription.
Action: wrap api calls in try-catch (js/ts) or try-except (python).
JS/TypeScript:
try {
const result = await client.preRecorded().transcribe("./audio.mp3");
} catch (error) {
if (error.message.includes("401")) {
console.error("invalid api key");
} else if (error.message.includes("timeout")) {
console.error("request timed out, will retry");
} else {
console.error("unexpected error:", error);
}
}
Python:
from gladiaio_sdk import GladiaClient, HttpError
try:
result = client.prerecorded().transcribe("audio.mp3")
except HttpError as e:
if e.status_code == 401:
print("invalid api key")
elif e.status_code == 429:
print("rate limited, backoff required")
except TimeoutError:
print("request timeout, retry manually")
except Exception as e:
print(f"unexpected error: {e}")
Output: errors caught and logged. sdk automatically retries transient failures (5xx, timeout) up to max retries; non-transient errors (4xx auth, validation) fail immediately.
Note: api rate limits (429) require client-side backoff; sdk does not auto-retry 429.
if user is building a js/ts or python project then use the SDK (always). sdk handles type safety, retry logic, polling, and audio upload.
if user needs custom http client or middleware (e.g., instrumentation, custom logging)
then use sdk first; configure via httpHeaders and httpTimeout. fall back to raw rest only if sdk config is insufficient.
if user's language has no official sdk (go, java, rust, c#, etc.) then use raw rest/websocket. see gladia-api-reference for raw endpoint docs.
if user explicitly requests raw http calls or is writing a ci script / curl one-off then raw rest is acceptable. for terminal one-offs, prefer gladia-using-cli if available.
default: when in doubt, use the sdk.
if user is embedding sdk in browser-side javascript then do NOT embed api key directly in front-end code. instead, set up a backend proxy: front-end calls your own backend endpoint, which forwards requests to gladia api with the key server-side. see ./references/javascript.md for proxy pattern code.
if api key is accidentally exposed (committed to git, logged, or visible in network tab) then immediately rotate key in console at https://console.gladia.io. revoked keys cannot be used even if copied.
if user is using node.js < 22 for live sessions (which require websocket)
then install the ws peer dependency manually: npm install ws. node.js 22+ has native websocket.
if user runs live session without ws on node < 22
then session fails silently (no error at time of startSession(), error surfaces on first sendAudio()).
if user calls client.prerecorded_async() or client.live_async() from synchronous code
then error: RuntimeError: no running event loop. solution: either (a) use sync client (client.prerecorded(), client.live()), or (b) wrap entire script in asyncio.run().
if user is inside an async def function
then use async clients (client.prerecorded_async(), client.live_async()).
if user is in europe or latency to us is unacceptable
then set region: "eu-west" (default). api endpoint: eu-west datacenter.
if user is in north america or eu latency is too high
then set region: "us-west". api endpoint: us-west datacenter.
if user needs to override api url (e.g., reverse proxy, custom deployment)
then set apiUrl parameter or GLADIA_API_URL env var. default: https://api.gladia.io.
if user experiences frequent timeout errors on slow networks or large files
then increase httpTimeout (default 30000 ms). example: httpTimeout: 120000 for 2-minute timeout.
if user experiences 5xx or transient network errors
then sdk auto-retries up to maxRetries times (default 3 for http, 5 for websocket). increase if needed: httpRetry: { maxRetries: 5 }.
if user experiences 429 (rate limit) errors then sdk does not auto-retry 429. implement client-side exponential backoff (wait 1s, 2s, 4s, etc. before retrying). gladia rate limits reset hourly.
apiKey, region, apiUrl, httpTimeout, httpRetry, wsTimeout, wsRetry (all set to provided or default values).preRecorded(), liveV2(), etc.) callable without error.Available methods: transcribe(audio, options), uploadFile(audio), create(options), createAndPoll(options), poll(jobId, config), get(jobId), delete(jobId), getFile(jobId).
Available methods: startSession(options) (returns LiveV2Session object), get(sessionId), delete(sessionId), getFile(sessionId).
Available methods: sendAudio(chunk), stopRecording(), endSession(), getSessionId().
Both sdks export request/response types:
JS/TypeScript:
import type {
LiveV2InitRequest,
LiveV2WebSocketMessage,
PreRecordedV2Response,
PreRecordedV2TranscriptionOptions,
} from "@gladiaio/sdk";
Python:
from gladiaio_sdk import (
LiveV2InitRequest,
LiveV2WebSocketMessage,
LiveV2LanguageConfig,
LiveV2MessagesConfig,
PreRecordedV2Response,
)
| Variable | Value |
|---|---|
GLADIA_API_KEY |
api key string (if used) |
GLADIA_REGION |
eu-west or us-west (if used) |
GLADIA_API_URL |
https://api.gladia.io or custom |
success: client object created without error, and user can call sub-client methods.
verification checklist:
npm list @gladiaio/sdk (js) or pip show gladiaio-sdk (python) returns package info with version.GLADIA_API_KEY set or passed to client constructor.const client = new GladiaClient(...) or client = GladiaClient(...) completes without throwing.client.preRecorded() (js) or client.prerecorded() (python) returns sub-client object.region matches user's choice (default eu-west).common failure modes and fixes:
ImportError: sdk not installed. run npm/pip install from step 1.ws (node < 22): install npm install ws.AttributeError: 'GladiaClient' object has no attribute 'prerecorded' (python): incorrect method name. js uses camelCase (preRecorded, liveV2), python uses snake_case (prerecorded, live).await on async call. all js sdk methods return promises.GladiaClient
├── preRecorded() → PreRecordedV2Client (JS)
│ prerecorded() → PreRecordedV2Client (Python)
│
├── liveV2() → LiveV2Client (JS)
│ live() → LiveV2Client (Python)
│
└── (Python only)
├── prerecorded_async() → AsyncPreRecordedV2Client
└── live_async() → AsyncLiveV2Client