Docs
TypeScript SDK
@trainingpipes/sdkis the official TypeScript client for the Training Pipes API. It's fully typed, tree-shakable, and generated from the same OpenAPI spec that powers the API reference.
Install
npm install @trainingpipes/sdkClass-based usage
import { TrainingPipes } from '@trainingpipes/sdk'
const tp = new TrainingPipes({
token: process.env.TRAINING_PIPES_TOKEN,
})
const { data, error } = await tp.raw.createBucket({
body: { name: 'training-data', region: 'us-east-1' },
})
if (error) throw error
console.log(data.id)Functional usage (tree-shakable)
import { createBucket, defaultClient } from '@trainingpipes/sdk'
defaultClient.setConfig({
baseUrl: 'https://api.trainingpipes.com',
headers: { Authorization: `Bearer ${token}` },
})
const { data } = await createBucket({
body: { name: 'training-data', region: 'us-east-1' },
})Dynamic tokens (Next.js example)
When using Clerk for auth in Next.js, pass a token function so each request resolves a fresh JWT:
import { TrainingPipes } from '@trainingpipes/sdk'
import { auth } from '@clerk/nextjs/server'
async function getTp() {
const { getToken } = await auth()
return new TrainingPipes({
baseUrl: process.env.NEXT_PUBLIC_API_URL,
token: async () => (await getToken()) ?? '',
})
}Error handling
Every operation returns { data, error, response }. Errors are typed per-endpoint, so you get autocompletion on the shape of 4xx responses:
const { data, error, response } = await tp.raw.getBucket({
path: { id: 'bkt_123' },
})
if (error) {
console.error(response.status, error.message)
return
}Types you can import
Every model from the spec is exported from the top-level package — e.g. Bucket, Connection, Mount, UsageReport, PlanWithFeatures:
import type { Bucket, Mount, UsageReport } from '@trainingpipes/sdk'
function summarize(report: UsageReport): string {
return `${report.current_total_bytes ?? 0} bytes across ${report.buckets?.length ?? 0} buckets`
}Regenerating the SDK (contributors)
make sdk-gen # re-run openapi-ts against backend/api/internal/docs/openapi.yaml
make sdk-build # produce dist/