> ## Documentation Index
> Fetch the complete documentation index at: https://docs.galileo.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Pydantic AI

> Learn how to integrate a Pydantic AI project with Galileo using OpenTelemetry

{/*<!-- markdownlint-enable MD044 -->*/}

Galileo supports logging traces from [Pydantic AI](https://ai.pydantic.dev/) applications using OpenTelemetry.

## Set up OpenTelemetry

To log Pydantic AI applications using Galileo, the first step is to set up OpenTelemetry.

<Steps>
  <Step title="Install the required packages">
    Add the Galileo Python SDK and Pydantic AI to your Python environment.

    <CodeGroup>
      ```bash Terminal theme={null}
      pip install pydantic-ai \
            galileo \
            opentelemetry-api \
            opentelemetry-sdk
      ```
    </CodeGroup>
  </Step>

  <Step title="Create environment variables for your Galileo settings">
    Set environment variables for your Galileo settings, for example in a `.env` file:

    <CodeGroup>
      ```ini .env theme={null}
      # Your Galileo API key
      GALILEO_API_KEY="your-galileo-api-key"

      # Your Galileo project name
      GALILEO_PROJECT="your-galileo-project-name"

      # The name of the Log stream you want to use for logging
      GALILEO_LOG_STREAM="your-galileo-log-stream "
      ```
    </CodeGroup>
  </Step>

  <Step title="Get your endpoint">
    The OTel endpoint is different from Galileo's regular API endpoint and is specifically designed to receive telemetry data in the OTLP format.

    If you are using:

    * **Galileo Cloud** at [app.galileo.ai](https://app.galileo.ai), then you don't need to provide a custom OTel endpoint.
      The default endpoint `https://api.galileo.ai/otel/traces` will be used automatically.

    * A **self-hosted Galileo deployment**, replace the `https://api.galileo.ai/otel/traces` endpoint with your deployment URL. The format of this URL is based on your console URL, replacing `console` with `api` and appending `/otel/traces`.

    For example:

    * if your console URL is `https://console.galileo.example.com`, the OTel endpoint would be `https://api.galileo.example.com/otel/traces`
    * if your console URL is `https://console-galileo.apps.mycompany.com`, the OTel endpoint would be `https://api-galileo.apps.mycompany.com/otel/traces`
  </Step>

  <Step title="Configure the OpenTelemetry tracer provider">
    Use the following code to configure OpenTelemetry with Galileo. This sets up the tracer provider and enables instrumentation for all Pydantic AI agents.

    ```python Python theme={null}
    from galileo import otel
    from opentelemetry import trace
    from opentelemetry.sdk.trace import TracerProvider
    from pydantic_ai import Agent

    # Create and configure the tracer provider
    provider = TracerProvider()
    trace.set_tracer_provider(provider)

    # Add the Galileo span processor
    otel.add_galileo_span_processor(
        tracer_provider=provider,
        processor=otel.GalileoSpanProcessor()
    )

    # Enable instrumentation on all agents
    Agent.instrument_all()
    ```
  </Step>
</Steps>

## What gets logged

Pydantic AI spans are automatically detected and normalized by Galileo's OpenTelemetry extension. The following span types are supported:

* **Agent runs**: Complete agent executions with input/output messages
* **Chat completions**: LLM calls with messages and responses
* **Tool executions**: Individual tool invocations with arguments and results
* **Tool workflows**: Parent spans that group multiple tool executions

For a complete working example, see the [Galileo SDK examples repository](https://github.com/rungalileo/sdk-examples).
