Skip to content

Go SDK

The official Pipe2.ai Go SDK provides type-safe GraphQL operations generated with genqlient. Every query and mutation is a typed Go function.

Installation

Terminal window
go get github.com/pipe2-ai/sdk-go

Quick start

package main
import (
"context"
"fmt"
"log"
pipe2 "github.com/pipe2-ai/sdk-go"
)
func main() {
ctx := context.Background()
client := pipe2.NewClient("YOUR_JWT_TOKEN")
// List all pipelines
resp, err := pipe2.GetPipelines(ctx, client)
if err != nil {
log.Fatal(err)
}
for _, p := range resp.Pipelines {
fmt.Printf("%s%d credits\n", p.Name, p.Credit_cost)
}
}

Authentication

Pass your JWT token when creating the client:

client := pipe2.NewClient("eyJhbGciOiJFZERTQSIs...")

Sign up

// Use an unauthenticated client for auth flows
auth := pipe2.NewClient("")
// 1. Start a signup flow
flow, err := pipe2.InitSignupFlow(ctx, auth)
// 2. Submit signup credentials
signup, err := pipe2.SubmitSignupFlow(ctx, auth,
flow.Init_signup_flow.Id,
"user@example.com",
"securepassword",
"Jane Doe",
flow.Init_signup_flow.Csrf_token,
)
// 3. Verify email (check inbox for the 6-digit code)
vflow, err := pipe2.InitVerificationFlow(ctx, auth, ptr("user@example.com"))
_, err = pipe2.SubmitVerificationCode(ctx, auth,
vflow.Init_verification_flow.Id,
"123456",
vflow.Init_verification_flow.Csrf_token,
)
// 4. Create an authenticated client with the token
client := pipe2.NewClient(*signup.Submit_signup_flow.Token)

Sign in

auth := pipe2.NewClient("")
// 1. Start a login flow
flow, err := pipe2.InitLoginFlow(ctx, auth)
// 2. Submit credentials
login, err := pipe2.SubmitLoginFlow(ctx, auth,
flow.Init_login_flow.Id,
"user@example.com",
"securepassword",
flow.Init_login_flow.Csrf_token,
nil, // referral_code (optional)
)
// 3. Use the token
client := pipe2.NewClient(*login.Submit_login_flow.Token)
pipelines, err := pipe2.GetPipelines(ctx, client)

Social login

social, err := pipe2.SubmitSocialLogin(ctx, auth, "google") // or "github", "microsoft"
// Redirect user to social.Submit_social_login.Redirect_url

Available operations

Pipelines

// List all pipelines
pipelines, err := pipe2.GetPipelines(ctx, client)
// Run a pipeline
run, err := pipe2.RunPipeline(ctx, client,
"baby-generator",
json.RawMessage(`{"photo_url_1":"https://...","photo_url_2":"https://..."}`),
)
fmt.Println("Run ID:", run.Run_pipeline.Run_id)
// Get a specific run
runDetail, err := pipe2.GetPipelineRun(ctx, client, "run-uuid")
// List run history
runs, err := pipe2.GetPipelineRuns(ctx, client, ptr(10), ptr(0), nil)

Assets

// Get a presigned upload URL
upload, err := pipe2.RequestUpload(ctx, client, "photo.jpg", "image/jpeg")
// PUT the file to upload.Request_upload.Upload_url
// Create an asset record
asset, err := pipe2.CreateAsset(ctx, client, "image", upload.Request_upload.Asset_url, []string{"input"})
// List your assets
assets, err := pipe2.GetUserAssets(ctx, client, nil, ptr(20), ptr(0))
// Delete an asset
_, err = pipe2.DeleteAssetAction(ctx, client, "asset-uuid")

Credits

// Check your balance
balance, err := pipe2.GetCreditBalance(ctx, client)
fmt.Printf("Available: %d\n", balance.Get_credit_balance.Available)
// View transaction history
history, err := pipe2.GetCreditHistory(ctx, client)

Personal access tokens

// Create a new token
token, err := pipe2.CreatePersonalAccessToken(ctx, client, "My Integration")
fmt.Println("Token:", token.Create_personal_access_token.Token)
// List tokens
tokens, err := pipe2.GetMyApiKeys(ctx, client)
// Revoke a token
_, err = pipe2.RevokePersonalAccessToken(ctx, client, "token-uuid")

Subscriptions

Watch a pipeline run status in real time via WebSocket. The SDK returns a typed Go channel:

// Start a pipeline
run, _ := pipe2.RunPipeline(ctx, client, "selfie-universe", inputJSON)
// Subscribe — returns a channel with typed updates
dataChan, subID, err := pipe2.WatchPipelineRun(ctx, wsClient, run.Run_pipeline.Run_id)
if err != nil {
log.Fatal(err)
}
for msg := range dataChan {
r := msg.Data.Pipeline_runs_by_pk
fmt.Printf("Status: %s\n", r.Status)
if r.Status == "completed" || r.Status == "failed" {
if len(r.Assets) > 0 {
fmt.Println("Result:", r.Assets[0].Url)
}
break
}
}