This guide will help you get started with the hosted version of phospho.

1

Get your phospho API key and your project id

Create an account on phospho.ai.

Don’t want to create an account? Get started with the local version of phospho.

2

Setup phospho logging in your app

Start logging using the Python Client, the JavaScript SDK or with the HTTP API. It takes on average 5 minutes for the basic setup.

3

Get insigths in the dashboard

Get analyses of your user interactions, explore the analytics and improve your app.

1. Get your phospho API key and your project id

Go to the phospho platform. Login or create an account if you don’t have one.

If this is your first time using phospho, a Default project has been created for you. On the main page, note down the project id and follow the link to create a new API key.

If you already have a project, go to Settings. Your project id is displayed on the top of the page. To create an API key, click on the Manage Organization & API keys button. Store your API key safely!

2. Setup phospho logging in your app

Add environment variables

In your code, add the following environment variables:

export PHOSPHO_API_KEY="your_api_key"
export PHOSPHO_PROJECT_ID="your_project_id"

Log tasks to phospho

Tasks are the basic bricks that make up your LLM apps. If you’re a programmer, you can think of tasks like functions.

A task is made of an input and an optional output, ideally readable by a human.

  • input (str): What goes into a task. Eg: what the user asks to the assistant.
  • output (Optional[str]): What goes out of the task. Eg: what the assistant replied to the user.

Example of tasks you can log to phospho: call to an LLM, answering a question, searching in documents, summarizing a text, performing inference of a model, steps of a chain-of-thought…

Tasks can be grouped into sessions. Tasks and Sessions can be attached to users.

How to setup logging?

The phospho Python module in the easiest way to log to phospho. It is compatible with Python 3.9+.

pip install --upgrade phospho

To log tasks, use phospho.log. The logged tasks are analyzed by the phospho analytics pipeline.

import phospho

# By default, phospho reads the PHOSPHO_API_KEY and PHOSPHO_PROJECT_ID from the environment variables
phospho.init()

# Example
input = "Hello! This is what the user asked to the system"
output = "This is the response showed to the user by the app."

# This is how you log a task to phospho
phospho.log(
  input=input,
  output=output,
  # Optional: for chats, group tasks together in sessions
  # session_id = "session_1",
  # Optional: attach tasks to users
  # user_id = "user_1",
  # Optional: add metadata to the task
  # metadata = {"system_prompt": "You are a helpful assistant."},
)

More about logging in Python

Did you know you could log OpenAI completions, streaming outputs and metadata? Learn more by clicking here.

3. Get insights in the dashboard

phospho extracts insights from the tasks logged. Discover the insights in the phospho dashboard.

Learn more about the insights you can get by reading our guides: