Guides

Getting Started with Pay-i

Thank you for being an early customer of Pay-i!

Overview

This documentation will describe Pay-i concepts, functionality, and code to get you up and running quickly.

At any time, you can send mail to [email protected] to report issues, ask questions, or get help.

🚀 Quickstart

Instrument your GenAI provider calls with Pay-i to automatically track costs, manage budgets, analyze usage patterns, and much more! This quickstart will guide you through the complete process from creating an application to viewing your tracked events.

1️⃣ Create an Application in Pay-i Developer Portal

Before you begin coding, you'll need to set up your application and get your API key:

  1. Log in to developer.pay-i.com

  2. Click on Private Apps button in the top-left corner

  3. Click on +Create Application button in the top-right corner

  4. Enter an application name (e.g., "Quickstart") and select a group

  5. Once created, new App Settings will open automatically. Under the API section, copy your Primary API Key for use in the next steps

Note about Groups: Each user gets their own default group that isn't shared with others. If you need to share applications with team members, you'll need to move them to a shared group. Groups help organize related applications and provide aggregated metrics. You can also share an App without putting it in a group and it will show under the Shared Apps.

Note: For more details on applications, see the Applications documentation.

2️⃣ Install SDK

Install the Pay-i SDK along with your AI provider's SDK:

pip install --upgrade payi openai
%pip install --upgrade payi openai

3️⃣ Set API keys

Create a .env file in your project directory (recommended):

  1. Install python-dotenv:
pip install python-dotenv
  1. Create a .env file with your API keys:
OPENAI_API_KEY=sk-...  # Your OpenAI API key
PAYI_API_KEY=api-...   # Your Pay-i API key from step 1
  1. Add .env to your .gitignore file to prevent accidentally committing your API keys.

For non-Python environments or alternatives, see Environment Variables.

4️⃣ Set up Pay-i Instrumentation

Initialize Pay-i instrumentation to track your GenAI usage:

import os
from dotenv import load_dotenv
from openai import OpenAI
from payi.lib.instrument import payi_instrument

# Load environment variables from .env file
load_dotenv()

# Initialize Pay-i instrumentation (automatically creates payi sync/async clients using environment variables)
payi_instrument()

# Configure OpenAI client for direct access
# OpenAI() automatically uses the OPENAI_API_KEY environment variable
client = OpenAI()

Need Block limits? If you require real-time budget enforcement with Block limits, you'll need to use Pay-i Proxy Configuration instead.

5️⃣ Use normally

Make API calls as usual with the configured client:

response = client.chat.completions.create(
    model="gpt-3.5-turbo",
    messages=[{"role": "user", "content": "Hello, world!"}]
)

print(response.choices[0].message.content)

6️⃣ View Your Events

After running your code, you can view your tracked events:

  1. Return to developer.pay-i.com
  2. Select your application (created in step 1)
  3. View your request activity, including costs and usage details in the dashboard

💡

Tip

Looking for more features? Check out:

📚 Example Notebooks

We have several Python notebooks that make it very easy to get up and running with popular Providers.

You can find the notebooks on our GitHub: Pay-i Quickstarts.

We suggest reading through the Pay-i Concepts section at a minimum, which will help you get the most out of Pay-i.

🛠️ Provider Configuration

We provide detailed guides for configuring Pay-i with popular LLM providers:

For a more general overview, check out our Auto-Instrumentation guide.

🧩 Decorators

Our Python Decorators provide an easy way to enhance Pay-i with business context, letting you annotate your functions with metadata that gets passed to Pay-i. This feature is currently only available in our Python SDK. If you would like to see this added for a different language, please contact [email protected].

📖 Interactive API Docs

Head on over to our API Reference to use our interactive API documentation. It requires a Pay-i API key, which you can learn more about in the Authentication section.


We're excited you're here! 💚