Skip to main content
Only Keywords AI users who are using the LLM proxy can set budget for their users. See how to set up LLM proxy for more information.
  • OpenAI Python SDK
  • OpenAI TypeScript SDK
  • Standard API
  • Other SDKs
Here is an example of how to send a user’s data with the parameter customer_params to Keywords AI in the OpenAI Python SDK.
from openai import OpenAI

client = OpenAI(
    base_url="https://api.keywordsai.co/api/",
    api_key="YOUR_KEYWORDSAI_API_KEY",
)

response = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[
        {"role": "user", "content": "Tell me a long story"}
    ],
    extra_body={
        "customer_params": {
            "customer_identifier": "customer_1",
            "budget_duration": "yearly",
            "period_budget": 1000,
            "total_budget": 10000 
        }
    }
)
You can also use period_start and period_end to set the budget period. In this case, you don’t need to set the budget_duration.

Parameters

period_start
string
The start date of the period. It should be in the format YYYY-MM-DD.
period_end
string
The start date of the period. It should be in the format YYYY-MM-DD.
budget_duration
string
Choices are yearly, monthly, weekly, and daily
period_budget
float
The budget for the period. It should be a float.
markup_percentage
float
The markup percentage for the period. Usage report of your customers through this key will be increased by this percentge.
total_budget
float
The total budget for a user.

Other ways to set budget

You can also set the budget to a specific user by calling the User Update endpoint or the User Creation endpoint for the new users.
I