Skip to content

pipeshub-ai/pipeshub-sdk-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pipeshub-sdk-go

pipeshub-sdk is the official Go client library for integrating Pipeshub into your product and internal tools

Summary

PipesHub API: Unified API documentation for PipesHub services.

PipesHub is an enterprise-grade platform providing:

  • User authentication and management
  • Document storage and version control
  • Knowledge base management
  • Enterprise search and conversational AI
  • Third-party integrations via connectors
  • System configuration management
  • Crawling job scheduling
  • Email services

Authentication

Most endpoints require JWT Bearer token authentication. Some internal endpoints use scoped tokens for service-to-service communication.

Base URLs

All endpoints use the /api/v1 prefix unless otherwise noted.

Table of Contents

SDK Installation

To add the SDK as a dependency to your project:

go get github.com/pipeshub-ai/pipeshub-sdk-go

SDK Example Usage

Example

package main

import (
	"context"
	pipeshub "github.com/pipeshub-ai/pipeshub-sdk-go"
	"github.com/pipeshub-ai/pipeshub-sdk-go/models/components"
	"log"
)

func main() {
	ctx := context.Background()

	s := pipeshub.New()

	res, err := s.UserAccount.InitAuth(ctx, components.InitAuthRequest{
		Email: "user@example.com",
	})
	if err != nil {
		log.Fatal(err)
	}
	if res.InitAuthResponse != nil {
		// handle response
	}
}

Authentication

Per-Client Security Schemes

This SDK supports the following security schemes globally:

Name Type Scheme Environment Variable
BearerAuth http HTTP Bearer PIPESHUB_BEARER_AUTH
Oauth2 oauth2 OAuth2 token PIPESHUB_OAUTH2

You can set the security parameters through the WithSecurity option when initializing the SDK client instance. The selected scheme will be used by default to authenticate with the API for all operations that support it. For example:

package main

import (
	"context"
	pipeshub "github.com/pipeshub-ai/pipeshub-sdk-go"
	"github.com/pipeshub-ai/pipeshub-sdk-go/models/components"
	"log"
	"os"
)

func main() {
	ctx := context.Background()

	s := pipeshub.New(
		pipeshub.WithSecurity(components.Security{
			BearerAuth: pipeshub.Pointer(os.Getenv("PIPESHUB_BEARER_AUTH")),
		}),
	)

	res, err := s.UserAccount.InitAuth(ctx, components.InitAuthRequest{
		Email: "user@example.com",
	})
	if err != nil {
		log.Fatal(err)
	}
	if res.InitAuthResponse != nil {
		// handle response
	}
}

Per-Operation Security Schemes

Some operations in this SDK require the security scheme to be specified at the request level. For example:

package main

import (
	"context"
	pipeshub "github.com/pipeshub-ai/pipeshub-sdk-go"
	"github.com/pipeshub-ai/pipeshub-sdk-go/models/components"
	"github.com/pipeshub-ai/pipeshub-sdk-go/models/operations"
	"log"
	"os"
)

func main() {
	ctx := context.Background()

	s := pipeshub.New()

	res, err := s.UserAccount.ResetPasswordWithToken(ctx, components.TokenPasswordResetRequest{
		Password: "H9GEHoL829GXj06",
	}, operations.ResetPasswordWithTokenSecurity{
		ScopedToken: os.Getenv("PIPESHUB_SCOPED_TOKEN"),
	})
	if err != nil {
		log.Fatal(err)
	}
	if res.PasswordResetResponse != nil {
		// handle response
	}
}

Available Resources and Operations

Available methods
  • List - List agent templates
  • Create - Create agent template
  • Get - Get agent template
  • Update - Update agent template
  • Delete - Delete agent template
  • SetGoogle - Configure Google authentication
  • SetOAuth - Configure generic OAuth provider
  • Get - Get connector configuration
  • Update - Update connector configuration
  • UpdateAuth - Update authentication configuration
  • UpdateFiltersSync - Update filters and sync configuration
  • Toggle - Toggle connector sync or agent
  • Get - Get metrics collection configuration
  • Toggle - Enable or disable metrics collection
  • ExchangeCode - Exchange OAuth authorization code for tokens
  • Update - Update OAuth config
  • Delete - Delete OAuth configuration
  • Get - Get current storage configuration
  • GetConfig - Get toolset configuration
  • Update - Update toolset configuration
  • Delete - Delete toolset configuration
  • Save - Save toolset configuration ⚠️ Deprecated

Server-sent event streaming

Server-sent events are used to stream content from certain operations. These operations will expose the stream as an iterable that can be consumed using a simple for loop. The loop will terminate when the server no longer has any events to send and closes the underlying connection.

package main

import (
	"context"
	pipeshub "github.com/pipeshub-ai/pipeshub-sdk-go"
	"github.com/pipeshub-ai/pipeshub-sdk-go/models/components"
	"log"
	"os"
)

func main() {
	ctx := context.Background()

	s := pipeshub.New(
		pipeshub.WithSecurity(components.Security{
			BearerAuth: pipeshub.Pointer(os.Getenv("PIPESHUB_BEARER_AUTH")),
		}),
	)

	res, err := s.Conversations.Stream(ctx, components.CreateConversationRequest{
		Query: "What are the key findings from our Q4 financial report?",
		RecordIds: []string{
			"507f1f77bcf86cd799439011",
			"507f1f77bcf86cd799439012",
		},
		ModelKey:  pipeshub.Pointer("gpt-4-turbo"),
		ModelName: pipeshub.Pointer("GPT-4 Turbo"),
		ChatMode:  pipeshub.Pointer("balanced"),
	})
	if err != nil {
		log.Fatal(err)
	}
	if res.SSEEvent != nil {
		defer res.SSEEvent.Close()

		for res.SSEEvent.Next() {
			event := res.SSEEvent.Value()
			log.Print(event)
			// Handle the event
		}
	}
}

Retries

Some of the endpoints in this SDK support retries. If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API. However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.

To change the default retry strategy for a single API call, simply provide a retry.Config object to the call by using the WithRetries option:

package main

import (
	"context"
	pipeshub "github.com/pipeshub-ai/pipeshub-sdk-go"
	"github.com/pipeshub-ai/pipeshub-sdk-go/models/components"
	"github.com/pipeshub-ai/pipeshub-sdk-go/retry"
	"log"
	"models/operations"
)

func main() {
	ctx := context.Background()

	s := pipeshub.New()

	res, err := s.UserAccount.InitAuth(ctx, components.InitAuthRequest{
		Email: "user@example.com",
	}, operations.WithRetries(
		retry.Config{
			Strategy: "backoff",
			Backoff: &retry.BackoffStrategy{
				InitialInterval: 1,
				MaxInterval:     50,
				Exponent:        1.1,
				MaxElapsedTime:  100,
			},
			RetryConnectionErrors: false,
		}))
	if err != nil {
		log.Fatal(err)
	}
	if res.InitAuthResponse != nil {
		// handle response
	}
}

If you'd like to override the default retry strategy for all operations that support retries, you can use the WithRetryConfig option at SDK initialization:

package main

import (
	"context"
	pipeshub "github.com/pipeshub-ai/pipeshub-sdk-go"
	"github.com/pipeshub-ai/pipeshub-sdk-go/models/components"
	"github.com/pipeshub-ai/pipeshub-sdk-go/retry"
	"log"
)

func main() {
	ctx := context.Background()

	s := pipeshub.New(
		pipeshub.WithRetryConfig(
			retry.Config{
				Strategy: "backoff",
				Backoff: &retry.BackoffStrategy{
					InitialInterval: 1,
					MaxInterval:     50,
					Exponent:        1.1,
					MaxElapsedTime:  100,
				},
				RetryConnectionErrors: false,
			}),
	)

	res, err := s.UserAccount.InitAuth(ctx, components.InitAuthRequest{
		Email: "user@example.com",
	})
	if err != nil {
		log.Fatal(err)
	}
	if res.InitAuthResponse != nil {
		// handle response
	}
}

Error Handling

Handling errors in this SDK should largely match your expectations. All operations return a response object or an error, they will never return both.

By Default, an API error will return apierrors.APIError. When custom error responses are specified for an operation, the SDK may also return their associated error. You can refer to respective Errors tables in SDK docs for more details on possible error types for each operation.

For example, the InitAuth function may return the following errors:

Error Type Status Code Content Type
apierrors.AuthError 400, 403, 404 application/json
apierrors.APIError 4XX, 5XX */*

Example

package main

import (
	"context"
	"errors"
	pipeshub "github.com/pipeshub-ai/pipeshub-sdk-go"
	"github.com/pipeshub-ai/pipeshub-sdk-go/models/apierrors"
	"github.com/pipeshub-ai/pipeshub-sdk-go/models/components"
	"log"
)

func main() {
	ctx := context.Background()

	s := pipeshub.New()

	res, err := s.UserAccount.InitAuth(ctx, components.InitAuthRequest{
		Email: "user@example.com",
	})
	if err != nil {

		var e *apierrors.AuthError
		if errors.As(err, &e) {
			// handle error
			log.Fatal(e.Error())
		}

		var e *apierrors.APIError
		if errors.As(err, &e) {
			// handle error
			log.Fatal(e.Error())
		}
	}
}

Server Selection

Select Server by Index

You can override the default server globally using the WithServerIndex(serverIndex int) option when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the indexes associated with the available servers:

# Server Variables Description
0 https://{instance_url}/api/v1 instance_url Base API URL
1 https://{instance_url} instance_url Root URL (used for MCP endpoints mounted at /mcp)

If the selected server has variables, you may override its default values using the associated option(s):

Variable Option Default Description
instance_url WithInstanceURL(instanceURL string) "https://app.pipeshub.com" Base server URL

Example

package main

import (
	"context"
	pipeshub "github.com/pipeshub-ai/pipeshub-sdk-go"
	"github.com/pipeshub-ai/pipeshub-sdk-go/models/components"
	"log"
)

func main() {
	ctx := context.Background()

	s := pipeshub.New(
		pipeshub.WithServerIndex(0),
		pipeshub.WithInstanceURL("https://app.pipeshub.com"),
	)

	res, err := s.UserAccount.InitAuth(ctx, components.InitAuthRequest{
		Email: "user@example.com",
	})
	if err != nil {
		log.Fatal(err)
	}
	if res.InitAuthResponse != nil {
		// handle response
	}
}

Override Server URL Per-Client

The default server can also be overridden globally using the WithServerURL(serverURL string) option when initializing the SDK client instance. For example:

package main

import (
	"context"
	pipeshub "github.com/pipeshub-ai/pipeshub-sdk-go"
	"github.com/pipeshub-ai/pipeshub-sdk-go/models/components"
	"log"
)

func main() {
	ctx := context.Background()

	s := pipeshub.New(
		pipeshub.WithServerURL("https://https://app.pipeshub.com"),
	)

	res, err := s.UserAccount.InitAuth(ctx, components.InitAuthRequest{
		Email: "user@example.com",
	})
	if err != nil {
		log.Fatal(err)
	}
	if res.InitAuthResponse != nil {
		// handle response
	}
}

Override Server URL Per-Operation

The server URL can also be overridden on a per-operation basis, provided a server list was specified for the operation. For example:

package main

import (
	"context"
	pipeshub "github.com/pipeshub-ai/pipeshub-sdk-go"
	"github.com/pipeshub-ai/pipeshub-sdk-go/models/operations"
	"log"
)

func main() {
	ctx := context.Background()

	s := pipeshub.New()

	res, err := s.OpenIDConnect.OauthAuthorizationServerMetadata(ctx, operations.WithServerURL(""))
	if err != nil {
		log.Fatal(err)
	}
	if res.OpenIDConfiguration != nil {
		// handle response
	}
}

Custom HTTP Client

The Go SDK makes API calls that wrap an internal HTTP client. The requirements for the HTTP client are very simple. It must match this interface:

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

The built-in net/http client satisfies this interface and a default client based on the built-in is provided by default. To replace this default with a client of your own, you can implement this interface yourself or provide your own client configured as desired. Here's a simple example, which adds a client with a 30 second timeout.

import (
	"net/http"
	"time"

	"github.com/pipeshub-ai/pipeshub-sdk-go"
)

var (
	httpClient = &http.Client{Timeout: 30 * time.Second}
	sdkClient  = pipeshub.New(pipeshub.WithClient(httpClient))
)

This can be a convenient way to configure timeouts, cookies, proxies, custom headers, and other low-level configuration.

About

pipeshub-sdk is the official Go client library for integrating Pipeshub into your product and internal tools

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages