> For the complete documentation index, see [llms.txt](https://docs.tolvyn.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.tolvyn.io/migrate-to-tolvyn/from-openai-direct.md).

# From OpenAI Direct

Two lines of code. That's it.

***

## What changes

1. Your API key (`sk-...` → `tlv_live_...`)
2. The base URL (`https://api.openai.com` → `https://proxy.tolvyn.io/v1/proxy/openai`)

Your prompts, models, parameters, and response format are completely unchanged. TOLVYN speaks OpenAI's API natively.

***

## Before / after

### Python

**Before:**

```python
from openai import OpenAI

client = OpenAI(api_key="sk-...")
```

**After:**

```python
from openai import OpenAI

client = OpenAI(
    api_key="tlv_live_...",
    base_url="https://proxy.tolvyn.io/v1/proxy/openai",
)
```

Add your real OpenAI key once in the TOLVYN dashboard (**Account → Provider Connections**). Your app code never holds a provider key again.

***

### Node.js

**Before:**

```js
import OpenAI from "openai";

const client = new OpenAI({ apiKey: "sk-..." });
```

**After:**

```js
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: "tlv_live_...",
  baseURL: "https://proxy.tolvyn.io/v1/proxy/openai",
});
```

***

### curl

**Before:**

```bash
curl https://api.openai.com/v1/chat/completions \
  -H "Authorization: Bearer sk-..." \
  -H "Content-Type: application/json" \
  -d '{"model":"gpt-4o","messages":[{"role":"user","content":"Hello"}]}'
```

**After:**

```bash
curl https://proxy.tolvyn.io/v1/proxy/openai/v1/chat/completions \
  -H "Authorization: Bearer tlv_live_..." \
  -H "Content-Type: application/json" \
  -d '{"model":"gpt-4o","messages":[{"role":"user","content":"Hello"}]}'
```

***

### Raw HTTP

**Before:**

```
POST /v1/chat/completions HTTP/1.1
Host: api.openai.com
Authorization: Bearer sk-...
Content-Type: application/json
```

**After:**

```
POST /v1/proxy/openai/v1/chat/completions HTTP/1.1
Host: proxy.tolvyn.io
Authorization: Bearer tlv_live_...
Content-Type: application/json
```

***

## What you get immediately

Once the two lines are changed, TOLVYN automatically:

* Logs every request with model, tokens, cost, and latency
* Calculates cost in real-time using live pricing data
* Stores an immutable audit ledger of all spend
* Lets you set budgets and get alerts when limits are approached

No configuration required. The dashboard is live the moment the first request goes through.

***

## Fail-open guarantee

If TOLVYN ever has an issue, requests automatically pass through to OpenAI. Your application never goes down because of TOLVYN. This is by design — TOLVYN is in your request path for observability, not for availability.

***

## Optional: add attribution headers

To see cost broken down by team, feature, or user in the dashboard:

```
X-Tolvyn-Team: backend-team
X-Tolvyn-Service: summarization
X-Tolvyn-Feature: report-gen
X-Tolvyn-User: user-123
X-Tolvyn-End-Customer: acme-corp
```

None of these are required. Add them incrementally as you need the visibility.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.tolvyn.io/migrate-to-tolvyn/from-openai-direct.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
