Zum Inhalt springen

TypeScript SDK

Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.

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

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: 'image-generator',
input: {
prompt: 'A cinematic sunset over mountains, wide angle, golden hour',
aspect_ratio: '16:9',
quality: 'fast',
},
});
// 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. 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 requests
const client = createClient(login.token!);
const { pipelines } = await client.GetPipelines();

Available operations

Pipelines

// List all pipelines with their schemas
const { 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 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 — 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 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 long-running pipeline
const { 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 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();