Documentation
¶
Overview ¶
LangChain integration for Payloop analytics.
Index ¶
- Variables
- type Attribution
- type Client
- func (c *Client) Close() error
- func (c *Client) HTTPClient(provider Provider) *http.Client
- func (c *Client) NewLangChainHandler() callbacks.Handler
- func (c *Client) NewTransaction() *Client
- func (c *Client) SetAttribution(attr *Attribution) error
- func (c *Client) Workflow(uuid string) *api.WorkflowClient
- func (c *Client) Workflows() *api.WorkflowsClient
- type Option
- type Provider
Constants ¶
This section is empty.
Variables ¶
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 ¶
New creates a Payloop client. If no API key is provided via options, it reads from PAYLOOP_API_KEY environment variable.
func (*Client) HTTPClient ¶ added in v0.1.3
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 ¶
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 ¶
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 WithAPIURL ¶
WithAPIURL sets a custom API endpoint (for testing).
func WithCollectorURL ¶
WithCollectorURL sets a custom collector endpoint (for testing).
func WithTimeout ¶
WithTimeout sets the HTTP timeout for analytics submission.