Skip to content

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

Terminal window
bun add @pipe2-ai/sdk

Quick start

import { createClient } from '@pipe2-ai/sdk';
const client = createClient('YOUR_JWT_TOKEN');
// List all pipelines
const { pipelines } = await client.GetPipelines();
// Run a pipeline
const { run_pipeline } = await client.RunPipeline({
pipeline_slug: 'selfie-universe',
input: { photo_url: 'https://...' },
});
// Check run status
const { 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 flows
const auth = createClient('');
// 1. Start a signup flow
const { init_signup_flow } = await auth.InitSignupFlow();
// 2. Submit signup credentials
const { 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 token
const client = createClient(submit_signup_flow.token!);

Sign in

import { createClient } from '@pipe2-ai/sdk';
const auth = createClient('');
// 1. Start a login flow
const { init_login_flow } = await auth.InitLoginFlow();
// 2. Submit credentials
const { 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 requests
const 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_url

Available operations

Pipelines

// List all pipelines with their schemas
const { pipelines } = await client.GetPipelines();
// Run a pipeline
const { run_pipeline } = await client.RunPipeline({
pipeline_slug: 'baby-generator',
input: {
photo_url_1: 'https://...',
photo_url_2: 'https://...',
},
});
// Get a specific run
const { pipeline_runs_by_pk } = await client.GetPipelineRun({ id: 'run-uuid' });
// List run history with pagination
const { pipeline_runs, pipeline_runs_aggregate } = await client.GetPipelineRuns({
limit: 10,
offset: 0,
});

Assets

// Get a presigned upload URL
const { 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
const { create_asset } = await client.CreateAsset({
asset_type: 'image',
url: request_upload.asset_url,
tags: ['input', 'selfie-universe'],
});
// List your assets
const { assets } = await client.GetUserAssets({ limit: 20 });
// Delete an asset (also removes from storage)
await client.DeleteAssetAction({ id: 'asset-uuid' });
// Update tags
await client.UpdateAssetTags({ id: 'asset-uuid', tags: ['favorite'] });

Credits

// Check your balance
const { get_credit_balance } = await client.GetCreditBalance();
console.log(`Available: ${get_credit_balance.available}`);
// View transaction history
const { get_credit_history } = await client.GetCreditHistory();

Personal access tokens

// Create a new token
const { create_personal_access_token } = await client.CreatePersonalAccessToken({
name: 'My Integration',
});
console.log(create_personal_access_token.token); // Save this — shown only once
// List tokens
const { personal_access_tokens } = await client.GetMyApiKeys();
// Revoke a token
await client.RevokePersonalAccessToken({ id: 'token-uuid' });

Subscriptions

Watch a pipeline run in real time. The SDK handles WebSocket connections automatically:

// Start a pipeline
const { run_pipeline } = await client.RunPipeline({
pipeline_slug: 'selfie-universe',
input: { photo_url: 'https://...' },
});
// Subscribe — async iterable with typed updates over WebSocket
for 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();