TypeScript SDK
Esta página aún no está disponible en tu idioma.
The official Pipe2.ai TypeScript SDK provides fully typed GraphQL operations generated from the API schema. Every query and mutation is a typed async function.
Source: github.com/pipe2-ai/sdk-typescript
Installation
bun add @pipe2-ai/sdknpm install @pipe2-ai/sdkpnpm add @pipe2-ai/sdkQuick start
import { createClient } from '@pipe2-ai/sdk';
const client = createClient('YOUR_JWT_TOKEN');
// List all pipelinesconst { pipelines } = await client.GetPipelines();
// Run a pipelineconst { run_pipeline } = await client.RunPipeline({ pipeline_slug: 'image-generator', input: { prompt: 'A cinematic sunset over mountains, wide angle, golden hour', aspect_ratio: '16:9', quality: 'fast', },});
// Check run statusconst { pipeline_runs_by_pk } = await client.GetPipelineRun({ id: run_pipeline.run_id,});Authentication
Pass your JWT token when creating the client:
const client = createClient('eyJhbGciOiJFZERTQSIs...');Sign up
import { createClient } from '@pipe2-ai/sdk';
// Use an unauthenticated client for auth flowsconst auth = createClient('');
// 1. Register (one call — the server runs the Kratos flow)const { register } = await auth.Register({ email: 'user@example.com', password: 'securepassword', name: 'Jane Doe',});
// 2. Verify email (check inbox for the 6-digit code)const { init_verification_flow } = await auth.InitVerificationFlow({ email: 'user@example.com',});await auth.SubmitVerificationCode({ flowId: init_verification_flow.id, code: '123456', csrf_token: init_verification_flow.csrf_token,});
// 3. Now create an authenticated client with the token. (register returns a// null token when email verification is required — sign in after verifying.)const client = createClient(register.token!);Sign in
import { createClient } from '@pipe2-ai/sdk';
const auth = createClient('');
// Log in (one call)const { login } = await auth.Login({ email: 'user@example.com', password: 'securepassword',});
// Use the token for all subsequent requestsconst client = createClient(login.token!);const { pipelines } = await client.GetPipelines();Available operations
Pipelines
// List all pipelines with their schemasconst { pipelines } = await client.GetPipelines();
// Run a pipeline that consumes an uploaded asset. The input references the// asset by id — create_asset returns that id after you PUT the file to the// presigned URL (see the "Assets" section below for the full upload flow).const { run_pipeline } = await client.RunPipeline({ pipeline_slug: 'transcription', input: { source_asset_id: assetId, language_code: 'auto', },});
// Get a specific runconst { pipeline_runs_by_pk } = await client.GetPipelineRun({ id: 'run-uuid' });
// List run history with paginationconst { pipeline_runs, pipeline_runs_aggregate } = await client.GetPipelineRuns({ limit: 10, offset: 0,});Assets
// Get a presigned upload URLconst { request_upload } = await client.RequestUpload({ filename: 'photo.jpg', content_type: 'image/jpeg',});// Upload the file to request_upload.upload_url via PUT
// Create an asset record — use create_asset.id as source_asset_id in// subsequent pipeline runs.const { create_asset } = await client.CreateAsset({ asset_type: 'video', url: request_upload.asset_url, tags: ['input'],});const assetId = create_asset.id;
// List your assetsconst { assets } = await client.GetUserAssets({ limit: 20 });
// Delete an asset (also removes from storage)await client.DeleteAssetAction({ id: 'asset-uuid' });
// Update tagsawait client.UpdateAssetTags({ id: 'asset-uuid', tags: ['favorite'] });Credits
// Check your balanceconst { get_credit_balance } = await client.GetCreditBalance();console.log(`Available: ${get_credit_balance.available}`);
// View transaction historyconst { get_credit_history } = await client.GetCreditHistory();Personal access tokens
// Create a new tokenconst { create_personal_access_token } = await client.CreatePersonalAccessToken({ name: 'My Integration',});console.log(create_personal_access_token.token); // Save this — shown only once
// List tokensconst { personal_access_tokens } = await client.GetMyApiKeys();
// Revoke a tokenawait client.RevokePersonalAccessToken({ id: 'token-uuid' });Subscriptions
Watch a pipeline run in real time. The SDK handles WebSocket connections automatically:
// Start a long-running pipelineconst { run_pipeline } = await client.RunPipeline({ pipeline_slug: 'video-generator', input: { prompt: 'A time-lapse of clouds over a mountain range' },});
// Subscribe — async iterable with typed updates over WebSocketfor await (const { pipeline_runs_by_pk: run } of client.WatchPipelineRun({ run_id: run_pipeline.run_id,})) { console.log(`Status: ${run?.status}`);
if (run?.status === 'completed' || run?.status === 'failed') { if (run?.assets?.length) { console.log('Result:', run.assets[0].url); } break; }}Plans & billing
const { plans } = await client.GetPlans();const { credit_packs } = await client.GetCreditPacks();const { subscriptions } = await client.GetSubscription();