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

# Drop-In Proxy

> Swap your OpenAI or Anthropic base URL to Curtly for instant dual-engine input and output token optimization.

Curtly provides a 100% OpenAI and Anthropic API-compatible reverse proxy. By simply pointing your client library's `baseURL` (or `base_url`) to `https://curtly.dev/v1`, your requests are automatically passed through both optimization engines:

1. **Input Stage**: Prompts and context chunks are parsed in-memory via Safe Vault and compressed.
2. **Output Stage**: Ponytail brevity directives are injected to prevent model verbosity.
3. **Forwarding**: The optimized payload is forwarded to your target provider (OpenAI, Anthropic, OpenRouter, Groq, or custom endpoints) with sub-5ms latency overhead.

***

## 1-Line Integration Examples

<CodeGroup>
  ```python Python (OpenAI SDK) theme={"dark"}
  from openai import OpenAI

  # 1-Line change: update base_url
  client = OpenAI(
      base_url="https://curtly.dev/v1",
      api_key="ctly_live_YOUR_CURTLY_KEY"
  )

  response = client.chat.completions.create(
      model="gpt-4o",
      messages=[
          {"role": "system", "content": "You are a code reviewer."},
          {"role": "user", "content": "Review this pull request for race conditions."}
      ]
  )
  print(response.choices[0].message.content)
  ```

  ```typescript TypeScript (openai-node) theme={"dark"}
  import OpenAI from 'openai';

  // 1-Line change: update baseURL
  const client = new OpenAI({
    baseURL: 'https://curtly.dev/v1',
    apiKey: process.env.CURTLY_API_KEY,
  });

  const response = await client.chat.completions.create({
    model: 'gpt-4o',
    messages: [{ role: 'user', content: 'Write an idempotent database migration script in SQL.' }],
  });
  console.log(response.choices[0].message.content);
  ```

  ```python Python (Anthropic Claude SDK) theme={"dark"}
  import anthropic

  # 1-Line change: update base_url
  client = anthropic.Anthropic(
      base_url="https://curtly.dev",
      api_key="ctly_live_YOUR_CURTLY_KEY"
  )

  message = client.messages.create(
      model="claude-3-5-sonnet-20241022",
      max_tokens=1024,
      messages=[
          {"role": "user", "content": "Analyze this Kubernetes deployment manifest."}
      ]
  )
  print(message.content[0].text)
  ```

  ```bash cURL (OpenAI Chat Completions) theme={"dark"}
  curl -X POST https://curtly.dev/v1/chat/completions \
    -H "Authorization: Bearer ctly_live_YOUR_CURTLY_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "gpt-4o",
      "messages": [
        { "role": "user", "content": "Explain how database indexing affects write throughput." }
      ]
    }'
  ```
</CodeGroup>

***

## Pass-Through Key Mode

You can also use Curtly in **Pass-Through Mode** by providing your raw provider key (`sk-...`, `sk-ant-...`, `sk-or-v1-...`). Curtly auto-detects the provider and forwards the request transparently using your own upstream quota without storing credentials.

```bash theme={"dark"}
curl -X POST https://curtly.dev/v1/chat/completions \
  -H "Authorization: Bearer sk-your-openai-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o",
    "messages": [{ "role": "user", "content": "Write a quicksort algorithm in Python." }]
  }'
```

***

## Streaming (SSE) Support

Curtly fully supports server-sent events (`stream: true`) for both OpenAI and Anthropic protocols with zero buffering delay:

```typescript theme={"dark"}
const stream = await client.chat.completions.create({
  model: 'gpt-4o-mini',
  messages: [{ role: 'user', content: 'Stream a 5-step deployment checklist.' }],
  stream: true,
});

for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content || '');
}
```

***

## Telemetry Response Headers

Every proxy response includes transparent token savings headers:

```http theme={"dark"}
HTTP/1.1 200 OK
Content-Type: application/json
X-Curtly-Original-Tokens: 384
X-Curtly-Input-Tokens: 198
X-Curtly-Input-Saved: 186
X-Curtly-Output-Saved-Est: 240
X-Curtly-Latency-Ms: 1.82
X-Curtly-Vault-Status: intact
```
