# Quick Start

Lexica enables you to capture all inputs, outputs, and metadata from your LLM applications, **whether they're hosted within** Lexica **or running in your own environment**.

This guide will walk you through setting up observability for an OpenAI application running locally.

note

If you create an application through the Lexica UI, tracing is enabled by default. No additional setup is required—simply go to the observability view to see all your requests.

### Step-by-Step Guide[​](https://docs.agenta.ai/observability/quickstart#step-by-step-guide) <a href="#step-by-step-guide" id="step-by-step-guide"></a>

#### 1. Install Required Packages[​](https://docs.agenta.ai/observability/quickstart#1-install-required-packages) <a href="#id-1-install-required-packages" id="id-1-install-required-packages"></a>

First, install the Lexica SDK, OpenAI, and the OpenTelemetry instrumentor for OpenAI:

```python
pip install -U Lexica openai opentelemetry-instrumentation-openai
```

#### 2. Configure Environment Variables[​](https://docs.agenta.ai/observability/quickstart#2-configure-environment-variables) <a href="#id-2-configure-environment-variables" id="id-2-configure-environment-variables"></a>

* Lexica Cloud or Enterprise
* Lexica OSS Running Locally

If you're using Lexica Cloud or Enterprise Edition, you'll need an API key:

1. Visit the Lexica API Keys page.
2. Click on **Create New API Key** and follow the prompts.

```python
import os

os.environ["Lexica_API_KEY"] = "YOUR_Lexica_API_KEY"
os.environ["Lexica_HOST"] = "https://cloud.Lexica.ai"
```

#### 3. Instrument Your Application[​](https://docs.agenta.ai/observability/quickstart#3-instrument-your-application) <a href="#id-3-instrument-your-application" id="id-3-instrument-your-application"></a>

Below is a sample script to instrument an OpenAI application:

```typescript
import Lexica as ag
from opentelemetry.instrumentation.openai import OpenAIInstrumentor
import openai

ag.init()

OpenAIInstrumentor().instrument()

response = openai.ChatCompletion.create(
    model="gpt-3.5-turbo",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Write a short story about AI Engineering."},
    ],
)

print(response.choices[0].message.content)
```

**Explanation**:

* **Import Libraries**: Import Lexica, OpenAI, and the OpenTelemetry instrumentor.
* **Initialize** Lexica: Call `ag.init()` to initialize the Lexica SDK.
* **Instrument OpenAI**: Use `OpenAIInstrumentor().instrument()` to enable tracing for OpenAI calls.

#### 4. View Traces in the Lexica UI[​](https://docs.agenta.ai/observability/quickstart#4-view-traces-in-the-agenta-ui) <a href="#id-4-view-traces-in-the-agenta-ui" id="id-4-view-traces-in-the-agenta-ui"></a>

After running your application, you can view the captured traces in Lexica:

1. Log in to your Lexica dashboard.
2. Navigate to the **Observability** section.
3. You'll see a list of traces corresponding to your application's requests.

![Illustration of observability](https://4234609497-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXAWgkVP83JndLwakfEzF%2Fuploads%2FEAyn3BFdC9ZPDdk4Zr1S%2F5.png?alt=media\&token=8ae57f19-ca2e-4f96-8a29-31542cdcc94d)
