Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:869413421 Ai moive studio APIKeyService create api key

From Leeroopedia
Knowledge Sources
Domains Security, Architecture
Last Updated 2026-10-23 12:00 GMT

Overview

Service that creates encrypted API key records by resolving the provider connection, encrypting the key via Fernet, and persisting to the database.

Description

'APIKeyService.create_api_key resolves the base URL via registry.connection, creates an APIKey model object, encrypts the plaintext key via key.set_api_key (which uses the EncryptionService singleton), and persists to the database.

The key is stored with status ACTIVE and the resolved base_url from the registry.

Usage

Import when registering new API keys. Called by the API key management endpoint.

Code Reference

Source Location

Signature

class APIKeyService(BaseService):
    async def create_api_key(
        self,
        user_id: str,
        name: str,
        provider: str,
        api_key: str,
        base_url: Optional[str] = None
    ) -> APIKey:
        """
        Args:
            user_id: owner UUID
            name: display name
            provider: provider name (openai/deepseek/volcengine/siliconflow/custom)
            api_key: plaintext API key
            base_url: optional custom base URL

        Returns:
            APIKey object with encrypted key
        """

Import

from src.services.api_key import APIKeyService

I/O Contract

Inputs

Name Type Required Description
user_id str Yes Owner UUID
name str Yes Display name
provider str Yes Provider name
api_key str Yes Plaintext API key
base_url str No Custom base URL

Outputs

Name Type Description
return value APIKey Model with encrypted key, resolved base_url, status=ACTIVE

Usage Examples

Creating an API Key

from src.services.api_key import APIKeyService

service = APIKeyService(db_session)
key = await service.create_api_key(
    user_id="user-uuid",
    name="My OpenAI Key",
    provider="openai",
    api_key="sk-...",
)
print(f"Key created: {key.id}, base_url: {key.base_url}")

Related Pages

Implements Principle

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment