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
}
}
)
Here is an example of how to send a user’s data with the parameter customer_params to Keywords AI in the OpenAI TypeScript SDK. In OpenAI TypeScript SDK, you should add a // @ts-expect-error before the metadata field.import { OpenAI } from "openai";
const client = new OpenAI({
baseURL: "https://api.keywordsai.co/api",
apiKey: "YOUR_KEYWORDSAI_API_KEY",
});
const response = await client.chat.completions
.create({
messages: [{ role: "user", content: "Say this is a test" }],
model: "gpt-4o-mini",
// @ts-expect-error
customer_params: {
"customer_identifier": "customer_1",
"budget_duration": "yearly",
"period_budget": 1000,
"total_budget": 10000
}
})
.asResponse();
console.log(await response.json());
import requests
def demo_call(input,
model="gpt-4o-mini",
token="YOUR_KEYWORDS_AI_API_KEY",
):
headers = {
'Content-Type': 'application/json',
'Authorization': f'Bearer {token}',
}
data = {
'model': model,
'messages': [{'role': 'user', 'content': input}],
'customer_params': {
"customer_identifier": "customer_1",
"budget_duration": "yearly",
"period_budget": 1000,
"total_budget": 10000
}
}
response = requests.post('https://api.keywordsai.co/api/chat/completions', headers=headers, json=data)
return response
messages = "Say 'Hello World'"
print(demo_call(messages).json())
We also support adding credentials in other SDKs or languages, please check out our integration section for more information.
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
The start date of the period. It should be in the format YYYY-MM-DD.
The start date of the period. It should be in the format YYYY-MM-DD.
Choices are yearly, monthly, weekly, and daily
The budget for the period. It should be a float.
The markup percentage for the period. Usage report of your customers through this key will be increased by this percentge.
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.