create_api_key
This module provides a Django management command to create a new API key for a user and account.
Classes
- Command
Implements the logic for the
manage.py create_api_keycommand.
Command-line Arguments
- –account_numberstr, optional
The Smarter account number to which the user belongs. Format: ####-####-####
- –usernamestr, optional
The username of the API key owner.
- –namestr, optional
The API key’s name, in snake_case. Refused if the owner already has a key with this name. Defaults to
<account_number>.<username>in snake_case, suffixed with_2,_3, … when the owner already has a key with that name.- –descriptionstr, optional
Optional brief text description for the API key.
Functionality
Finds the specified user and account using the provided arguments.
Creates a new API key (auth token) for the given user profile, with a name that none of the owner’s other keys has: a cli command or console page finds a key by its owner and name.
Outputs the API key value and relevant information. Warns that the key is only shown once.
Displays instructions for associating the API key with an LLMClient.
Usage Example
python manage.py create_api_key –account_number=1234-5678-9012 –username=myuser –description=”integration key”
- class smarter.apps.account.management.commands.create_api_key.Command(stdout=None, stderr=None, no_color=False, force_color=False)[source]
Bases:
SmarterCommandDjango manage.py create_user command.
This command is used to create a new user for an account.
- smarter.apps.account.management.commands.create_api_key.api_key_name_exists(user, name)[source]
Return True if the user already has an API key with this name.