SDK quickstart: TypeScript / JavaScript
Generate a typed client for the /v1 Developer API from its OpenAPI spec and
make your first call. Works for Node and the browser (server-side for anything
holding an API key — never ship a secret key to a browser).
No hand-written SDK is published yet — you generate one from the live spec. An official TypeScript SDK is a roadmap item.
1. Get the spec
The live, machine-readable contract:
https://api-dev.traxstreaming.live/v1/openapi.json
2. Generate a typed client
Two good options — pick one.
Option A — types + a tiny typed fetch wrapper (recommended, lightweight):
npm i -D openapi-typescript
npm i openapi-fetch
npx openapi-typescript https://api-dev.traxstreaming.live/v1/openapi.json -o src/trax-api.d.ts
Option B — a full generated client (heavier, more ceremony):
npm i -D @openapitools/openapi-generator-cli
npx openapi-generator-cli generate \
-i https://api-dev.traxstreaming.live/v1/openapi.json \
-g typescript-fetch -o src/trax-client
3. Authenticate
Create an API key from your account's Developer / API Keys screen (copy the
sk_live_… secret once), and keep it server-side — an environment variable, not
in source:
export TRAX_API_KEY=sk_live_xxxxxxxxxxxxxxxxxxxxxxxx
4. First call
Using openapi-fetch with the generated types:
import createClient from 'openapi-fetch'
import type { paths } from './trax-api'
const trax = createClient<paths>({
baseUrl: 'https://api-dev.traxstreaming.live',
headers: { Authorization: `Bearer ${process.env.TRAX_API_KEY}` },
})
// List your studios (requires the studios:read scope)
const { data, error, response } = await trax.GET('/v1/studios', {
params: { query: { limit: 50 } },
})
console.log('request id:', response.headers.get('X-Request-Id'))
if (error) {
// One envelope for every error: { error: { code, message, requestId } }
console.error(error.error.code, error.error.message)
} else {
for (const studio of data.data) console.log(studio.id, studio.name)
if (data.nextCursor) {
// pass data.nextCursor as ?cursor= to page — see /reference/pagination
}
}
Or with plain fetch, no codegen at all:
const res = await fetch('https://api-dev.traxstreaming.live/v1/studios?limit=50', {
headers: { Authorization: `Bearer ${process.env.TRAX_API_KEY}` },
})
const body = await res.json()
if (!res.ok) throw new Error(body.error.code) // 'invalid_key' | 'rate_limited' | …
console.log(body.data, body.nextCursor)
Next
- Pagination — loop
nextCursorto read a full list. - Errors — branch on
error.code; retry only transient codes. - Rate limits — honor
Retry-Afteron429. - Build a client — add real-time control (WebSocket) and media (WebRTC) for a full app; use OAuth when acting as a user.