Documentation
¶
Overview ¶
Package tokentip is the official Go client for the TokenTip API — tips that buy AI inference credit for open-source maintainers. It has no dependencies outside the standard library.
Index ¶
- Constants
- Variables
- func IsConflict(err error) bool
- func IsForbidden(err error) bool
- func IsNotFound(err error) bool
- func IsUnauthorized(err error) bool
- func IsUpstream(err error) bool
- type Ack
- type ApiToken
- type Balance
- type Client
- func (c *Client) Balance(ctx context.Context) (*Balance, error)
- func (c *Client) CreateWebhook(ctx context.Context, in NewWebhook) (*WebhookEndpointCreated, error)
- func (c *Client) DeleteWebhook(ctx context.Context, id string) error
- func (c *Client) GetKey(ctx context.Context) (*Key, error)
- func (c *Client) GetTip(ctx context.Context, id string) (*Tip, error)
- func (c *Client) ListTips(ctx context.Context, opts *ListOptions) (*TipList, error)
- func (c *Client) ListTokens(ctx context.Context) ([]ApiToken, error)
- func (c *Client) ListWebhooks(ctx context.Context) ([]WebhookEndpoint, error)
- func (c *Client) Me(ctx context.Context) (*Me, error)
- func (c *Client) OperatorDisableKey(ctx context.Context, handle string) (*Ack, error)
- func (c *Client) OperatorListCreators(ctx context.Context, opts *ListOptions) (*CreatorList, error)
- func (c *Client) OperatorListTips(ctx context.Context, opts *ListOptions) (*TipList, error)
- func (c *Client) OperatorOverview(ctx context.Context) (*Overview, error)
- func (c *Client) OperatorSettle(ctx context.Context, tipID, idempotencyKey string) (*ForceSettleResult, error)
- func (c *Client) RevokeToken(ctx context.Context, id string) error
- func (c *Client) RotateKey(ctx context.Context, idempotencyKey string) (*MintedKey, error)
- func (c *Client) Stats(ctx context.Context) (*Stats, error)
- func (c *Client) StreamEvents(ctx context.Context, operator bool) (*EventStream, error)
- type CreatorList
- type CreatorSummary
- type Error
- type Event
- type EventStream
- type ForceSettleResult
- type Key
- type ListOptions
- type Me
- type MintedKey
- type Money
- type NewWebhook
- type Option
- type Overview
- type Pool
- type Stats
- type Tip
- type TipList
- type WebhookEndpoint
- type WebhookEndpointCreated
Constants ¶
const DefaultTolerance = 5 * time.Minute
DefaultTolerance is the accepted clock skew between the signature timestamp and now when verifying a webhook.
Variables ¶
var ErrInvalidSignature = errors.New("tokentip: invalid webhook signature")
ErrInvalidSignature is returned by VerifyWebhook when a delivery cannot be trusted — malformed header, timestamp outside tolerance, or a signature mismatch.
Functions ¶
func IsConflict ¶
func IsForbidden ¶
func IsNotFound ¶
func IsUnauthorized ¶
func IsUpstream ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) CreateWebhook ¶
func (c *Client) CreateWebhook(ctx context.Context, in NewWebhook) (*WebhookEndpointCreated, error)
func (*Client) ListTokens ¶ added in v0.2.0
func (*Client) ListWebhooks ¶
func (c *Client) ListWebhooks(ctx context.Context) ([]WebhookEndpoint, error)
func (*Client) OperatorDisableKey ¶
func (*Client) OperatorListCreators ¶
func (c *Client) OperatorListCreators(ctx context.Context, opts *ListOptions) (*CreatorList, error)
func (*Client) OperatorListTips ¶
func (*Client) OperatorOverview ¶
func (*Client) OperatorSettle ¶
func (*Client) RevokeToken ¶ added in v0.2.0
func (*Client) StreamEvents ¶
StreamEvents opens the creator stream (GET /v1/events), or the system-wide operator stream when operator is true. The stream stays open until the context is cancelled or Close is called.
type CreatorList ¶
type CreatorList struct {
Data []CreatorSummary `json:"data"`
NextCursor *string `json:"next_cursor"`
}
type CreatorSummary ¶
type CreatorSummary struct {
Handle string `json:"handle"`
Balance Money `json:"balance"`
KeyClaimed bool `json:"key_claimed"`
DisplayName *string `json:"display_name"`
Fingerprint *string `json:"fingerprint"`
LiveUsage *Money `json:"live_usage"`
LiveLimit *Money `json:"live_limit"`
Disabled *bool `json:"disabled"`
SettledTips *int `json:"settled_tips"`
SettledGross *Money `json:"settled_gross"`
Joined *time.Time `json:"joined"`
}
type Error ¶
type Error struct {
Status int `json:"status"`
Title string `json:"title"`
Detail string `json:"detail"`
Type string `json:"type"`
Instance string `json:"instance"`
}
Error is the typed form of an RFC 7807 problem+json response.
type Event ¶
type Event struct {
ID string `json:"id"`
Type string `json:"type"`
Created time.Time `json:"created"`
Scope string `json:"scope"`
APIVersion string `json:"api_version"`
Data json.RawMessage `json:"data"`
}
Event is one item on the live stream or a webhook delivery. Data holds the event-specific payload; use Tip / Balance or Decode to read it.
func VerifyWebhook ¶
func VerifyWebhook(payload []byte, signatureHeader, secret string, tolerance time.Duration) (*Event, error)
VerifyWebhook checks the X-TokenTip-Signature header against the raw request body and the endpoint's signing secret, then returns the decoded event. Pass tolerance == 0 to use DefaultTolerance. It returns ErrInvalidSignature on a malformed header, a stale timestamp, or a signature mismatch.
func (*Event) Balance ¶
Balance returns the post-transition credit balance on settled/disputed events.
type EventStream ¶
type EventStream struct {
// contains filtered or unexported fields
}
EventStream is a live server-sent-events subscription to the tip lifecycle. Call Next until it returns io.EOF, then Close.
func (*EventStream) Close ¶
func (s *EventStream) Close() error
func (*EventStream) Next ¶
func (s *EventStream) Next() (*Event, error)
Next blocks until the next event arrives, returning io.EOF when the stream ends. Events carry an idempotency ID; dedupe on it, as TokenTip may redeliver.
type ForceSettleResult ¶
type ListOptions ¶
ListOptions are the shared cursor-pagination + filter parameters.
type Money ¶
type Money string
Money is an exact USD amount as a decimal string (six-decimal precision). It is never a float, to avoid binary rounding on money.
type NewWebhook ¶
type Option ¶
type Option func(*Client)
func WithBaseURL ¶
WithBaseURL overrides the API host (for testing or staging).
func WithHTTPClient ¶
WithHTTPClient supplies a custom *http.Client (timeouts, proxies, transport).
type Tip ¶
type Tip struct {
ID string `json:"id"`
CreatorHandle string `json:"creator_handle"`
Status string `json:"status"`
Gross Money `json:"gross"`
NetToTokens Money `json:"net_to_tokens"`
TipperName *string `json:"tipper_name"`
TipperNote *string `json:"tipper_note"`
CreatedAt time.Time `json:"created_at"`
HeldAt *time.Time `json:"held_at"`
SettledAt *time.Time `json:"settled_at"`
}
type WebhookEndpoint ¶
type WebhookEndpointCreated ¶
type WebhookEndpointCreated struct {
WebhookEndpoint
Secret string `json:"secret"`
}