# Set up Verlon in this project

You are a coding agent. The person you work for pasted "Set up Verlon in this project. Follow verlon.ai/setup." These are the steps. Follow them in order.

Verlon is an LLM gateway. The app keeps the provider SDK it already uses (OpenAI, Anthropic, Gemini, Mistral) and points it at Verlon. No Verlon package is installed. Each call you move gets its own **endpoint**: a name for what the call does, holding the model the call uses today. The code then sends the endpoint's name where it sent the model, so the person can change the model later from the dashboard with no code change.

## Rules

- **Change nothing until the person picks a call.** Step 1 only reads.
- **Never write an API key into code, a commit or your output.** Read it from the `VERLON_API_KEY` environment variable. If it isn't set, ask the person to set it; never invent one.
- **Move one call at a time.** Every other call keeps working exactly as before.
- **Keep the provider key and the old path** until step 5 shows the moved call arrived.

## 1. Map every model call

Find every place the code calls a model. For each one, note:

- the file and line;
- the provider SDK (or plain HTTP);
- the model it names;
- what it does, in a few words;
- whether it streams;
- its kind: chat (including tools and structured output), embeddings, image, video, speech to text (`stt`), text to speech (`tts`), moderation or OCR.

Show the person that list. Suggest which call to move first: the lowest-risk one is a low-volume, non-streaming call off the user's critical path. Ask which call they want to move, then wait for the answer.

## 2. The key

The person creates a Verlon API key at https://verlon.ai/dashboard/keys and sets it as `VERLON_API_KEY` wherever the app reads its environment (`.env`, the deploy's secrets). Keys start with `sk-vrln-`.

## 3. The call's endpoint

Get a name from what the call does. Verlon returns one that follows the name rules and is free in the account:

```bash
curl -s https://api.verlon.ai/v1/gates/suggest-name \
  -H "Authorization: Bearer $VERLON_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "sentence": "Summarizes a support ticket for the agent on call" }'
```

It answers `{ "name": "summarizes-support-ticket" }`. Show the person the name; they can pick another. A name is lowercase letters, digits and single hyphens, starting with a letter, up to 64 characters. It can't be a model's or a provider's name, look like an id, or be one of the dashboard's own page words.

Create the endpoint with the model the call names now, and the call's kind from step 1 as `taskType` (`chat`, `embeddings`, `image`, `video`, `stt`, `tts`, `moderation` or `ocr`):

```bash
curl -s https://api.verlon.ai/v1/gates \
  -H "Authorization: Bearer $VERLON_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "summarizes-support-ticket",
    "model": "<the call'\''s model>",
    "taskType": "chat",
    "description": "Summarizes a support ticket for the agent on call"
  }'
```

A `201` returns the endpoint. Then:

- **`409`:** the name is taken. Read that endpoint (`GET https://api.verlon.ai/v1/gates/name/<name>`). If its `model` and `taskType` are the ones you asked for, it's this call's endpoint from an earlier run: reuse it. Otherwise use the name the error's `details.suggestion` gives, or ask the person for another.
- **`400` about the name:** use `details.suggestion`, or ask the person.
- **`400` about the model:** Verlon doesn't serve that model under that name. Show the person the error and stop.
- **`400` about the type:** the call's kind from step 1 doesn't match the model's type. Check the kind again, or leave out `taskType` to use the model's own.

If the `verlon` CLI is installed, `verlon endpoint create --name <name> --model <model> --type <kind> --description "<what it does>"` does the same, and reuses the endpoint it made on an earlier run.

## 4. Move the call

Change only the client that call uses, the base URL and the key, and in the call itself replace the model with the endpoint's name. Leave everything else in the call as it is.

**OpenAI SDK (TypeScript)**

```typescript
import OpenAI from 'openai';

const summarizer = new OpenAI({
  baseURL: 'https://api.verlon.ai/v1',
  apiKey: process.env.VERLON_API_KEY,
});

// in the call:
//   model: 'summarizes-support-ticket',
```

**OpenAI SDK (Python)**

```python
import os

from openai import OpenAI

summarizer = OpenAI(
    base_url="https://api.verlon.ai/v1",
    api_key=os.environ["VERLON_API_KEY"],
)

# in the call:
#   model="summarizes-support-ticket",
```

**Anthropic SDK (TypeScript)**

```typescript
import Anthropic from '@anthropic-ai/sdk';

const summarizer = new Anthropic({
  baseURL: 'https://api.verlon.ai',
  apiKey: process.env.VERLON_API_KEY,
});

// in the call:
//   model: 'summarizes-support-ticket',
```

**Anthropic SDK (Python)**

```python
import os

from anthropic import Anthropic

summarizer = Anthropic(
    base_url="https://api.verlon.ai",
    api_key=os.environ["VERLON_API_KEY"],
)

# in the call:
#   model="summarizes-support-ticket",
```

**Gemini SDK (TypeScript)**

```typescript
import { GoogleGenAI } from '@google/genai';

const summarizer = new GoogleGenAI({
  apiKey: process.env.VERLON_API_KEY,
  httpOptions: { baseUrl: 'https://api.verlon.ai' },
});

// in the call:
//   model: 'summarizes-support-ticket',
```

**Mistral SDK:** set `serverURL` to `https://api.verlon.ai/mistral` and the key to `VERLON_API_KEY`. More: https://docs.verlon.ai/provider-compatibility/mistral.

**Plain HTTP:** send the same request to the same path on `https://api.verlon.ai` (for example `/v1/chat/completions` or `/v1/messages`), with the Verlon key where the request sent the provider's key, and the endpoint's name as the model.

If the app builds one shared client for many calls, create a second client for the moved call rather than changing the shared one.

## 5. Check it

Send one request through the moved call's path (or run that code once). For an OpenAI-format call:

```bash
curl -si https://api.verlon.ai/v1/chat/completions \
  -H "Authorization: Bearer $VERLON_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "model": "summarizes-support-ticket", "messages": [{ "role": "user", "content": "Hello" }] }'
```

It worked if the status is `200` and the response has an `x-verlon-served-model` header naming the model that answered. A `404` with the code `no_endpoint_named` means the name in the code doesn't match the endpoint's; the error lists the account's endpoints.

Then confirm Verlon recorded it on the endpoint:

```bash
curl -s "https://api.verlon.ai/v1/gates/performance/by-endpoint?window=24h" \
  -H "Authorization: Bearer $VERLON_API_KEY"
```

The entry whose `gateId` is the endpoint's `id` (from step 3) counts its `requests` and `errors`. Tell the person where to look: the dashboard's Endpoints page, where the endpoint shows the call's requests, cost and latency.

## 6. Optional: trace an agent

If the code is an agent (a loop of model calls and tools), its runs can appear as traces with standard OpenTelemetry, still with no Verlon package. Follow https://docs.verlon.ai/platform/agent-gates. The essentials:

- export spans to `OTEL_EXPORTER_OTLP_ENDPOINT=https://api.verlon.ai` with `OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer $VERLON_API_KEY"`;
- mark each run with one span carrying `gen_ai.operation.name=invoke_agent` and `gen_ai.conversation.id=<the conversation's id>`;
- in Node, add `@opentelemetry/instrumentation-undici` so the provider SDK's calls join the run; in Python, pass `propagate.inject(headers)` as `extra_headers`.

## 7. The rest

The person moves the other calls when they're ready, one endpoint each, the same way: a new project in one pass, a large app as a slow rollout. Nothing else changes.

## Good to know

- **Errors keep the provider's own shape**, so the app's existing error handling still works.
- **The endpoint holds the model.** The person can change it, or add fallback models, on the endpoint's page in the dashboard, with no code change.
- **Plan limits apply to the key's account.** A `402` or `429` from Verlon is a billing or rate answer, not an outage.
- More: https://docs.verlon.ai
