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
go get github.com/pipe2-ai/sdk-goQuick 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 flowsauth := pipe2.NewClient("")
// 1. Start a signup flowflow, err := pipe2.InitSignupFlow(ctx, auth)
// 2. Submit signup credentialssignup, 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 tokenclient := pipe2.NewClient(*signup.Submit_signup_flow.Token)Sign in
auth := pipe2.NewClient("")
// 1. Start a login flowflow, err := pipe2.InitLoginFlow(ctx, auth)
// 2. Submit credentialslogin, 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 tokenclient := 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_urlAvailable operations
Pipelines
// List all pipelinespipelines, err := pipe2.GetPipelines(ctx, client)
// Run a pipelinerun, 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 runrunDetail, err := pipe2.GetPipelineRun(ctx, client, "run-uuid")
// List run historyruns, err := pipe2.GetPipelineRuns(ctx, client, ptr(10), ptr(0), nil)Assets
// Get a presigned upload URLupload, err := pipe2.RequestUpload(ctx, client, "photo.jpg", "image/jpeg")// PUT the file to upload.Request_upload.Upload_url
// Create an asset recordasset, err := pipe2.CreateAsset(ctx, client, "image", upload.Request_upload.Asset_url, []string{"input"})
// List your assetsassets, err := pipe2.GetUserAssets(ctx, client, nil, ptr(20), ptr(0))
// Delete an asset_, err = pipe2.DeleteAssetAction(ctx, client, "asset-uuid")Credits
// Check your balancebalance, err := pipe2.GetCreditBalance(ctx, client)fmt.Printf("Available: %d\n", balance.Get_credit_balance.Available)
// View transaction historyhistory, err := pipe2.GetCreditHistory(ctx, client)Personal access tokens
// Create a new tokentoken, err := pipe2.CreatePersonalAccessToken(ctx, client, "My Integration")fmt.Println("Token:", token.Create_personal_access_token.Token)
// List tokenstokens, 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 pipelinerun, _ := pipe2.RunPipeline(ctx, client, "selfie-universe", inputJSON)
// Subscribe — returns a channel with typed updatesdataChan, 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 }}