Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:BerriAI Litellm CLI Token Utils

From Leeroopedia
Revision as of 12:08, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/BerriAI_Litellm_CLI_Token_Utils.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Attribute Value
Sources litellm/litellm_core_utils/cli_token_utils.py
Domains Authentication, CLI
Last Updated 2026-02-15 16:00 GMT

Overview

SDK-level utilities for reading CLI authentication tokens stored on disk after litellm-proxy login.

Description

This module provides three functions for managing CLI-based authentication tokens. Tokens are stored as JSON files at ~/.litellm/token.json. The module has zero dependencies on proxy code, making it safe to import at the SDK level. It reads the token file, parses the JSON, and extracts the API key for use with the LiteLLM SDK.

Usage

Import get_litellm_gateway_api_key in Python scripts to automatically retrieve the API key created by the litellm-proxy login CLI command, avoiding the need to hardcode or manually pass API keys.

Code Reference

Source Location

litellm/litellm_core_utils/cli_token_utils.py (58 lines)

Signature

def get_cli_token_file_path() -> str
def load_cli_token() -> Optional[dict]
def get_litellm_gateway_api_key() -> Optional[str]

Import

from litellm.litellm_core_utils.cli_token_utils import (
    get_cli_token_file_path,
    load_cli_token,
    get_litellm_gateway_api_key,
)

I/O Contract

get_cli_token_file_path

Direction Name Type Description
Output return str Absolute path to ~/.litellm/token.json

load_cli_token

Direction Name Type Description
Output return Optional[dict] Parsed JSON token data, or None if file is missing or malformed

get_litellm_gateway_api_key

Direction Name Type Description
Output return Optional[str] The stored API key string, or None if not available

Usage Examples

import litellm
from litellm.litellm_core_utils.cli_token_utils import get_litellm_gateway_api_key

# Retrieve the API key saved by `litellm-proxy login`
api_key = get_litellm_gateway_api_key()
if api_key:
    response = litellm.completion(
        model="gpt-3.5-turbo",
        messages=[{"role": "user", "content": "Hello"}],
        api_key=api_key,
        base_url="https://your-proxy.com/v1",
    )

# Check the token file path
from litellm.litellm_core_utils.cli_token_utils import get_cli_token_file_path
print(get_cli_token_file_path())
# /home/user/.litellm/token.json

Related Pages

Page Connections

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