Skip to main content

Javascript SDK

LLM Strategy

Wrap any LLM model from the @ai-sdk/* library, to automatically fire prompt- & completion tokens used by every model call.

Ingestion Payload

Python SDK

The Python SDK has no ingestion helper or strategies. Send usage events with polar.events.ingest from the Python SDK instead.

Ingesting events

events.ingest sends the request synchronously. To avoid blocking your request path, batch events and send them from a background task, or use PolarAsync in asynchronous applications.

PydanticAI

PydanticAI is an AI agent framework for Python. A common use-case with AI applications is to track the usage of LLMs, like the number of input and output tokens, and bill the customer accordingly. Read the token usage from the agent run and ingest it as an event:
This example is inspired from the Pydantic Model example of PydanticAI documentation.

Ingestion Payload