Skip to content

Logfire SDK CLI: SDK Command Line Interface Guide

Logfire comes with a CLI used for authentication and project management:

usage: logfire [-h] [--version] [--base-url BASE_URL | --region {us,eu}]  ...

The CLI for Pydantic Logfire.

options:
  -h, --help           show this help message and exit
  --version            show the version and exit

global options:
  --base-url BASE_URL  the base URL for self-hosted Logfire instances (e.g.,
                       http://localhost:8080)
  --region {us,eu}     the region to use

commands:
  
    auth               Authenticate with Logfire.
    clean              Remove the contents of the Logfire data directory.
    inspect            Inspect installed packages and recommend packages that
                       might be useful.
    whoami             Show user authenticated username and the URL to your
                       Logfire project.
    projects           Project management for Logfire.
    read-tokens        Manage read tokens for a project
    prompt             Creates a prompt to be used with your favorite LLM. The
                       prompt assumes you are using Logfire MCP.
    info               Show versions of logfire, OS and related packages.
    run                Run Python scripts/modules with Logfire instrumentation

See https://logfire.pydantic.dev/docs/reference/cli/ for more detailed
documentation.

Authentication (auth)

You need to be authenticated to use the Logfire.

To authenticate yourself, run the auth command in the terminal:

Terminal
logfire auth

You will be prompted to select a data region (EU or US). To specify this via the cli instead of interactively, use logfire --region eu auth or logfire --region us auth

Then you will be given the option to open logfire in your browser: Terminal screenshot with Logfire auth command

After pressing "Enter", you will be redirected to the browser to log in to your account.

Browser screenshot with Logfire login page

Then, if you go back to the terminal, you’ll see that you are authenticated! πŸŽ‰

Terminal screenshot with successful authentication

Log out (auth logout)

To log out and remove the locally stored credentials, run:

Terminal
logfire auth logout

Clean (clean)

To clean most the files created by Logfire, run the following command:

Terminal
logfire clean

The clean command doesn’t remove the logs, and the authentication information stored in the ~/.logfire directory.

To also remove the logs, you can run the following command:

Terminal
logfire clean --logs

AI Gateway (gateway)

The gateway command runs a local OAuth proxy for the Logfire AI Gateway and can launch supported AI coding tools with short-lived credentials.

Install the optional dependencies before using it:

Terminal
uv add "logfire[gateway]"

Launch a supported integration through the proxy:

Terminal
logfire gateway launch claude

You can also run only the proxy and configure a tool manually:

Terminal
logfire gateway serve

Use --device-flow if browser callback authorization is not available, or pass --region eu / --region us before gateway to select the Logfire region.

Inspect (inspect)

The inspect command is used to identify the missing OpenTelemetry instrumentation packages in your project.

To inspect your project, run the following command:

Terminal
logfire inspect

This will output the projects you need to install to have optimal OpenTelemetry instrumentation.

Terminal screenshot with Logfire inspect command

Info (info)

To print the versions of logfire, your operating system, and related (OpenTelemetry) packages (useful when reporting a bug) run:

Terminal
logfire info

Who Am I (whoami)

To show the currently authenticated user and the URL of the current Logfire project, run:

Terminal
logfire whoami

If you have one or more tokens configured (e.g. via the LOGFIRE_TOKEN environment variable), this shows the project each token belongs to instead.

Projects

List (projects list)

To check the projects you have access to, run the following command:

Terminal
logfire projects list

You’ll see something like this:

Terminal
❯ logfire projects list
┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┓
┃ Organization ┃ Project        ┃
┑━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━┩
β”‚ Kludex       β”‚ backend        β”‚
β”‚ Kludex       β”‚ worker         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Use (projects use)

To use an already created project, run the following command:

Terminal
logfire projects use <project-name>

For example, to use the backend project, you can run:

Terminal
logfire projects use backend

Create (projects new)

To create a new project, run the following command:

Terminal
logfire projects new <project-name>

Follow the instructions, and you’ll have a new project created in no time! πŸ₯³

Read tokens (read-tokens)

To create a read token for a project and print it to stdout, run:

Terminal
logfire read-tokens --project <org>/<project> create

Because the token is printed to stdout, this composes well with other tools, e.g. configuring the Logfire MCP server:

Terminal
claude mcp add logfire -e LOGFIRE_READ_TOKEN=$(logfire read-tokens --project <org>/<project> create) -- uvx logfire-mcp@latest

Run (run)

To run a Python script or module with Logfire instrumentation enabled automatically for all installed packages that have an available OpenTelemetry instrumentation, run:

Terminal
logfire run script.py
# or run a module, forwarding any arguments after it:
logfire run -m my_module --my-arg

By default a summary box is printed to stderr showing which packages were instrumented; disable it with --no-summary. Use --exclude to skip instrumenting specific packages:

Terminal
logfire run --exclude sqlalchemy,fastapi script.py

Prompt (prompt)

To generate a prompt for an LLM to investigate an issue in your project (assuming the Logfire MCP server is configured), run:

Terminal
logfire prompt "why are my requests slow?"

Use --claude, --codex, or --opencode to verify (and set up) the MCP configuration for the respective coding tool, --update to replace an existing Logfire MCP server configuration, and --project <org>/<project> to select the project.