> ## 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.

# SDKs & Wrappers

> Client wrappers and middleware examples for OpenAI SDK and Vercel AI SDK.

Curtly can be integrated into existing model client pipelines to preprocess prompts and context windows.

***

## 1. Node.js Client Wrapper

```typescript theme={"dark"}
async function compressPrompt(rawPrompt: string, mode: 'conservative' | 'balanced' | 'aggressive' = 'balanced'): Promise<string> {
  const response = await fetch('https://curtly.dev/api/v1/compress', {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${process.env.CURTLY_API_KEY}`,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      prompt: rawPrompt,
      mode,
    }),
  });

  if (!response.ok) {
    return rawPrompt;
  }

  const data = await response.json();
  return data.compressed || rawPrompt;
}

// Example usage before dispatching to an LLM
const systemPrompt = `You are an expert fullstack software engineer. 
Please note that you must always return clean, modular TypeScript code.`;

const optimizedPrompt = await compressPrompt(systemPrompt, 'balanced');
```

***

## 2. Next.js API Route Integration

```typescript theme={"dark"}
import { streamText } from 'ai';

export async function POST(req: Request) {
  const { messages, systemPrompt } = await req.json();

  let optimizedSystem = systemPrompt;
  try {
    const curtlyRes = await fetch('https://curtly.dev/api/v1/compress', {
      method: 'POST',
      headers: {
        'Authorization': `Bearer ${process.env.CURTLY_API_KEY}`,
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        prompt: systemPrompt,
        mode: 'balanced',
      }),
    });

    if (curtlyRes.ok) {
      const data = await curtlyRes.json();
      optimizedSystem = data.compressed || systemPrompt;
    }
  } catch (err) {
    console.error('Compression fallback:', err);
  }

  // Pass optimizedSystem to your model provider
}
```

***

## 3. Python Integration

```python theme={"dark"}
import os
import requests

CURTLY_API_KEY = os.environ.get("CURTLY_API_KEY")

def compress_prompt(prompt: str, mode: str = "balanced") -> str:
    try:
        res = requests.post(
            "https://curtly.dev/api/v1/compress",
            headers={"Authorization": f"Bearer {CURTLY_API_KEY}"},
            json={"prompt": prompt, "mode": mode},
            timeout=5
        )
        if res.status_code == 200:
            return res.json().get("compressed", prompt)
    except Exception as e:
        print(f"Curtly error, falling back to raw prompt: {e}")
    return prompt

# Preprocess context prior to model invocation
context = compress_prompt("You are a data assistant. Please note that you must analyze the logs accurately.")
```
