MagickMind
PythonResources

Api Keys (v1)

Reference for magick_mind.resources.v1.api_keys.

magick_mind.resources.v1.api_keys

API Keys resource for Magick Mind SDK v1 API.

Provides methods for managing API keys for authenticated requests.

ApiKeysResourceV1

class ApiKeysResourceV1(BaseResource)

Resource client for API key operations.

ApiKeysResourceV1.create

async def create(user_id: str,
                 project_id: str,
                 models: list[str],
                 key_alias: str,
                 duration: Optional[str] = None,
                 team_id: Optional[str] = None,
                 max_budget: Optional[float] = None) -> CreateApiKeyResponse

Create a new API key.

Arguments:

  • user_id - User ID that owns this key
  • project_id - Project ID to associate with
  • models - List of allowed model names
  • key_alias - Human-readable key name
  • duration - Optional validity duration (e.g., '30d', '1y')
  • team_id - Optional team ID
  • max_budget - Optional spending limit

Returns:

CreateApiKeyResponse with the new API key

Raises:

  • ProblemDetailsException - If the request fails

Example:

response = await client.v1.api_keys.create( ... user_id="user-123", ... project_id="proj-456", ... models=["gpt-4", "gpt-3.5-turbo"], ... key_alias="Production Key", ... duration="90d", ... max_budget=100.0 ... ) print(f"API Key: {response.key.key}")

ApiKeysResourceV1.list

async def list(user_id: str) -> ListApiKeysResponse

List all API keys for a user.

Arguments:

  • user_id - User ID to list keys for

Returns:

ListApiKeysResponse with list of API keys

Raises:

  • ProblemDetailsException - If the request fails

Example:

response = await client.v1.api_keys.list(user_id="user-123") for key in response.keys: ... print(f"{key.key_alias}: {key.key_id}")

ApiKeysResourceV1.update

async def update(key: str,
                 models: list[str],
                 key_alias: str,
                 duration: Optional[str] = None,
                 max_budget: Optional[float] = None) -> UpdateApiKeyResponse

Update an existing API key.

Arguments:

  • key - The API key to update
  • models - Updated list of allowed models
  • key_alias - Updated key alias/name
  • duration - Optional updated validity duration
  • max_budget - Optional updated spending limit

Returns:

UpdateApiKeyResponse with updated key details

Raises:

  • ProblemDetailsException - If the request fails

Example:

response = await client.v1.api_keys.update( ... key="sk-...", ... models=["gpt-4", "claude-3"], ... key_alias="Updated Production Key", ... max_budget=200.0 ... )

ApiKeysResourceV1.delete

async def delete(key_id: str) -> DeleteApiKeyResponse

Delete an API key.

Arguments:

  • key_id - The key ID to delete

Returns:

DeleteApiKeyResponse with confirmation

Raises:

  • ProblemDetailsException - If the request fails

Example:

response = await client.v1.api_keys.delete(key_id="key-abc-123") print(response.message)

On this page