payloop

package module
v0.1.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 10, 2025 License: MIT Imports: 17 Imported by: 0

README

Welcome to Payloop!

Cost Visibility for AI Agents

Payloop is a lightweight infrastructure layer that gives AI teams real-time visibility into the true costs of deploying agents - across tasks, workflows, and customers. Most teams today can’t see what it actually costs to deploy their agents, making it nearly impossible to manage gross margins or price with confidence.

With just a single line of code, Payloop delivers:

  • Cost tracking across OpenAI, Anthropic, Gemini, and more in one place
  • Breakdowns by task, agent, and customer in real time
  • Confidence to deploy the right pricing model (cost-plus, token-based, outcome-based, etc.) while preserving gross margins

Watch a short demo video: Payloop Walkthrough Video

By surfacing exactly what’s driving cost and value, Payloop becomes the source of truth for agent economics - helping founders and operators scale their agents with confidence.

Sign up here: trypayloop.com

Installation

go get github.com/PayloopAI/go-sdk

Documentation

Our SDK reference provides documentation for:

  • Understanding how Payloop works
  • Demonstrating how to integrate Payloop into your product
  • Code samples to illustrate our SDK and API

Check it out here: developers.trypayloop.com

Documentation

Overview

LangChain integration for Payloop analytics.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidClient indicates the provider client is not the expected type.
	ErrInvalidClient = errors.New("invalid client type")

	// ErrAlreadyRegistered indicates the client is already wrapped.
	ErrAlreadyRegistered = errors.New("client already registered")

	// ErrMissingAPIKey indicates no API key was provided.
	ErrMissingAPIKey = errors.New("API key required")

	// ErrInvalidAttribution indicates attribution validation failed.
	ErrInvalidAttribution = errors.New("invalid attribution")
)

Functions

This section is empty.

Types

type Attribution

type Attribution struct {
	ParentID       string
	ParentName     *string
	SubsidiaryID   *string
	SubsidiaryName *string
}

Attribution tracks cost hierarchy for an invocation. ParentID is required. All other fields are optional.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client tracks LLM costs across providers.

func New

func New(opts ...Option) (*Client, error)

New creates a Payloop client. If no API key is provided via options, it reads from PAYLOOP_API_KEY environment variable.

func (*Client) Close

func (c *Client) Close() error

Close gracefully shuts down the client, ensuring all analytics are sent.

func (*Client) HTTPClient added in v0.1.3

func (c *Client) HTTPClient(provider Provider) *http.Client

HTTPClient returns an HTTP client configured to track analytics for the specified provider. Use this client when creating your own provider clients (OpenAI, Anthropic, Google, etc.).

Example:

payloop, _ := payloop.New(payloop.WithAPIKey("..."))
httpClient := payloop.HTTPClient(payloop.ProviderOpenAI)
openaiClient := openai.NewClient(openai.WithHTTPClient(httpClient), openai.WithAPIKey("..."))

func (*Client) NewLangChainHandler

func (c *Client) NewLangChainHandler() callbacks.Handler

NewLangChainHandler creates a LangChain callback handler with Payloop analytics tracking. Use this with LangChain's callback system to automatically track LLM calls.

func (*Client) NewTransaction

func (c *Client) NewTransaction() *Client

NewTransaction returns a client with a fresh transaction ID. The original client is unmodified (value semantics).

func (*Client) SetAttribution

func (c *Client) SetAttribution(attr *Attribution) error

SetAttribution sets attribution on the client, affecting all future requests. This method mutates the client in place.

func (*Client) Workflow

func (c *Client) Workflow(uuid string) *api.WorkflowClient

Workflow returns a client for managing a specific workflow.

func (*Client) Workflows

func (c *Client) Workflows() *api.WorkflowsClient

Workflows returns a client for managing workflows.

type Option

type Option func(*config) error

Option configures a Client.

func WithAPIKey

func WithAPIKey(key string) Option

WithAPIKey sets the Payloop API key.

func WithAPIURL

func WithAPIURL(url string) Option

WithAPIURL sets a custom API endpoint (for testing).

func WithCollectorURL

func WithCollectorURL(url string) Option

WithCollectorURL sets a custom collector endpoint (for testing).

func WithTimeout

func WithTimeout(d time.Duration) Option

WithTimeout sets the HTTP timeout for analytics submission.

type Provider added in v0.1.3

type Provider string

Provider represents a supported LLM provider.

const (
	// ProviderOpenAI represents the OpenAI API provider.
	ProviderOpenAI Provider = "openai"

	// ProviderAnthropic represents the Anthropic API provider.
	ProviderAnthropic Provider = "anthropic"

	// ProviderGoogle represents the Google GenAI API provider.
	ProviderGoogle Provider = "google"
)

Directories

Path Synopsis
examples
anthropic command
google command
invocation command
langchain command
openai command
streaming command
workflow command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL