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_key command.

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: SmarterCommand

Django manage.py create_user command.

This command is used to create a new user for an account.

add_arguments(parser)[source]

Add arguments to the command.

handle(*args, **options)[source]

Create the api key.

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.

Parameters:
  • user (User) – The API key’s owner.

  • name (str) – The name, in snake_case, as API key names are stored.

Return type:

bool

Returns:

True if one of the user’s API keys has this name.

smarter.apps.account.management.commands.create_api_key.unused_api_key_name(user, base_name)[source]

Return the base name in snake_case, suffixed with _2, _3, … if the user already has an API key with it.

Parameters:
  • user (User) – The API key’s owner.

  • base_name (str) – The preferred name.

Return type:

str

Returns:

A name that none of the user’s API keys has.