Credit Groups

openwebui_token_tracking.credit_groups.create_credit_group(credit_group_name, credit_allowance, description, database_url=None)[source]

Creates a credit group in the database.

Parameters:
  • credit_group_name (str) – Name of the credit group to be created.

  • credit_allowance (int) – Maximum credit allowance granted to members of this group.

  • description (str) – Description e of the credit group to be created.

  • database_url (str, optional) – URL of the database. If None, uses env variable DATABASE_URL

Raises:

KeyError – Raised if a credit group of this name already exists.

openwebui_token_tracking.credit_groups.get_credit_group(credit_group_name, database_url=None)[source]

Retrieves a credit group from the database by its name and returns it as a dictionary.

Parameters:
  • credit_group_name (str) – Name of the credit group to retrieve

  • database_url (str, optional) – URL of the database. If None, uses env variable DATABASE_URL

Returns:

Dictionary containing the credit group properties (id, name, max_credit, description)

Return type:

dict

Raises:

KeyError – Raised if the credit group of that name could not be found

openwebui_token_tracking.credit_groups.list_credit_groups(database_url=None)[source]

Lists all credit groups in the database in a readable format.

Parameters:

database_url (str, optional) – URL of the database. If None, uses env variable DATABASE_URL

Returns:

List of dictionaries containing formatted credit group information

Return type:

list[dict]

openwebui_token_tracking.credit_groups.update_credit_group(credit_group_name, new_credit_allowance=None, new_description=None, new_name=None, database_url=None)[source]

Updates an existing credit group in the database.

Parameters:
  • credit_group_name (str) – Name of the credit group to update

  • new_credit_allowance (int, optional) – New maximum credit allowance for the group

  • new_description (str, optional) – New description for the group

  • new_name (str, optional) – New name for the group

  • database_url (str, optional) – URL of the database. If None, uses env variable DATABASE_URL

Raises:
  • KeyError – Raised if the credit group of that name could not be found

  • ValueError – Raised if no updates are specified

openwebui_token_tracking.credit_groups.upsert_credit_group(credit_group_name, credit_allowance, description, database_url=None)[source]

Creates a new credit group or updates an existing one if it already exists.

Parameters:
  • credit_group_name (str) – Name of the credit group

  • credit_allowance (int) – Maximum credit allowance for the group

  • description (str) – Description of the credit group

  • database_url (str, optional) – URL of the database. If None, uses env variable DATABASE_URL

Returns:

True if a new group was created, False if an existing group was updated

Return type:

bool

openwebui_token_tracking.credit_groups.delete_credit_group(credit_group_name, database_url=None, force=False)[source]

Deletes a credit group from the database.

Parameters:
  • credit_group_name (str) – Name of the credit group to delete

  • database_url (str, optional) – URL of the database. If None, uses env variable DATABASE_URL

  • force (bool, optional) – If True, deletes group even if it has users. If False, raises error if group has users

Raises:
  • KeyError – Raised if the credit group of that name could not be found

  • ValueError – Raised if the group has users and force=False

openwebui_token_tracking.credit_groups.add_user(user_id, credit_group_name, database_url=None)[source]

Add the specified user to the credit group

Parameters:
  • credit_group_name (str) – Name of the credit group to add the user to

  • user_id (str) – ID of the user

  • database_url (str, optional) – URL of the database. If None, uses env variable DATABASE_URL

Raises:

KeyError – Raised if the credit group of that name could not be found

openwebui_token_tracking.credit_groups.remove_user(user_id, credit_group_name, database_url=None)[source]

Removes a user from the specified credit group.

Parameters:
  • user_id (str) – ID of the user to remove

  • credit_group_name (str) – Name of the credit group to remove the user from

  • database_url (str, optional) – URL of the database. If None, uses env variable DATABASE_URL

Raises:
  • KeyError – Raised if the credit group of that name could not be found

  • ValueError – Raised if the user is not in the specified credit group

openwebui_token_tracking.credit_groups.list_users(credit_group_name, database_url=None)[source]

Lists all users in a specific credit group.

Parameters:
  • credit_group_name (str) – Name of the credit group to list users from

  • database_url (str, optional) – URL of the database. If None, uses env variable DATABASE_URL

Returns:

List of dictionaries containing user information

Return type:

list[dict]

Raises:

KeyError – Raised if the credit group of that name could not be found