TypeScript SDK
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.
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: 'selfie-universe', input: { photo_url: 'https://...' },});
// 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. Start a signup flowconst { init_signup_flow } = await auth.InitSignupFlow();
// 2. Submit signup credentialsconst { submit_signup_flow } = await auth.SubmitSignupFlow({ flowId: init_signup_flow.id, email: 'user@example.com', password: 'securepassword', name: 'Jane Doe', csrf_token: init_signup_flow.csrf_token,});
// 3. 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,});
// 4. Now create an authenticated client with the tokenconst client = createClient(submit_signup_flow.token!);Sign in
import { createClient } from '@pipe2-ai/sdk';
const auth = createClient('');
// 1. Start a login flowconst { init_login_flow } = await auth.InitLoginFlow();
// 2. Submit credentialsconst { submit_login_flow } = await auth.SubmitLoginFlow({ flowId: init_login_flow.id, email: 'user@example.com', password: 'securepassword', csrf_token: init_login_flow.csrf_token,});
// 3. Use the token for all subsequent requestsconst client = createClient(submit_login_flow.token!);const { pipelines } = await client.GetPipelines();Social login
const { submit_social_login } = await auth.SubmitSocialLogin({ provider: 'google', // or 'github', 'microsoft'});// Redirect the user to submit_social_login.redirect_urlAvailable operations
Pipelines
// List all pipelines with their schemasconst { pipelines } = await client.GetPipelines();
// Run a pipelineconst { run_pipeline } = await client.RunPipeline({ pipeline_slug: 'baby-generator', input: { photo_url_1: 'https://...', photo_url_2: 'https://...', },});
// 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 recordconst { create_asset } = await client.CreateAsset({ asset_type: 'image', url: request_upload.asset_url, tags: ['input', 'selfie-universe'],});
// 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 pipelineconst { run_pipeline } = await client.RunPipeline({ pipeline_slug: 'selfie-universe', input: { photo_url: 'https://...' },});
// 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();