Metadata-Version: 2.4
Name: freesolo
Version: 0.1.4
Summary: OpenAI, Anthropic, and Gemini tracing package for LLM applications.
Requires-Python: >=3.10
Requires-Dist: httpx>=0.27.0
Provides-Extra: dev
Requires-Dist: ruff>=0.11.0; extra == 'dev'
Provides-Extra: examples
Requires-Dist: anthropic>=0.40.0; extra == 'examples'
Requires-Dist: google-genai>=1.0.0; extra == 'examples'
Requires-Dist: openai>=1.0.0; extra == 'examples'
Description-Content-Type: text/markdown

# freesolo

`freesolo` is a Python tracing package for LLM apps.

For the Node/npm package, see [`npm/`](./npm).

It is built for the lowest-friction integration possible:

1. Install the package
2. Set `FREESOLO_API_KEY`
3. Wrap your OpenAI, Anthropic, Gemini, or OpenAI-compatible client
4. Call the client normally

## Current provider support

`freesolo` currently supports automatic client instrumentation for:

- OpenAI
- Anthropic
- Gemini
- OpenAI-compatible clients via `wrap(...)` / `wrap_provider(...)`

## Install

Install the package plus the provider SDK you use:

```bash
pip install freesolo openai
```

or

```bash
pip install freesolo anthropic
```

or

```bash
pip install freesolo google-genai
```

## Environment

- `FREESOLO_API_KEY`

## Quickstart

```python
from openai import OpenAI
from freesolo import wrap

client = wrap(OpenAI())

result = client.responses.create(
    model="gpt-4.1-mini",
    instructions="Reply in plain text.",
    input=[
        {
            "role": "user",
            "content": [{"type": "input_text", "text": "How do I reset my password?"}],
        }
    ],
)

print(result.output_text or "")
```

## OpenRouter Quickstart

```python
from openai import OpenAI
from freesolo import wrap

client = wrap(
    OpenAI(
        base_url="https://openrouter.ai/api/v1",
        api_key="YOUR_OPENROUTER_API_KEY",
    )
)

response = client.chat.completions.create(
    model="openai/gpt-4.1-mini",
    messages=[
        {"role": "system", "content": "Reply in plain text."},
        {"role": "user", "content": "Write a one-sentence launch blurb."},
    ],
    max_tokens=120,
)

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

## Gemini Quickstart

```python
from google import genai
from freesolo import instrument_gemini

client = instrument_gemini(genai.Client())

response = client.models.generate_content(
    model="gemini-2.5-flash",
    contents="Write a one-sentence release note for traced Gemini support.",
)

print(response.text or "")
```

## Group Multiple Model Calls

For agentic or long-horizon tasks, strongly prefer wrapping the whole task in `start_trace(...)` so all of the model calls land in one trace.

For a single one-off OpenAI, Anthropic, or Gemini request, you can skip it.

```python
from anthropic import Anthropic
from freesolo import instrument_anthropic, start_trace

client = instrument_anthropic(Anthropic())

with start_trace("support-agent-run"):
    first = client.messages.create(
        model="claude-sonnet-4-20250514",
        max_tokens=64,
        messages=[{"role": "user", "content": "Say hello"}],
    )
    second = client.messages.create(
        model="claude-sonnet-4-20250514",
        max_tokens=64,
        messages=[{"role": "user", "content": "Say goodbye"}],
    )
```

## What Gets Stored

- Trace title if you explicitly pass it to `start_trace("...")`
- Trace metadata if you explicitly pass it to `start_trace(..., metadata=...)`
- Input payloads with `system_prompt`, `user_prompt`, and `images`
- Output payloads as plain text
- Token usage when available
- Image inputs with inline previews for the trace UI

## Notes

- You do not need `@trace()` for ordinary LLM tracing.
- A single instrumented OpenAI, Anthropic, or Gemini request creates a trace automatically.
- For OpenAI-compatible providers like OpenRouter, prefer `wrap(...)` instead of provider-specific helpers.
- For agentic or long-horizon workflows, strongly recommend `start_trace("descriptive-title")` so planning, retries, and follow-up calls stay grouped.
- Delivery is best-effort by default. Trace ingestion failures do not break your app.
