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

# Vercel AI SDK

> TokenLab'i OpenAI uyumlu veya Responses-native sağlayıcıları kullanarak Vercel AI SDK ile entegre edin

## Genel Bakış

<Note>
  **Tür**: Framework veya Platform

  **Birincil Yol**: OpenAI uyumlu varsayılan

  **Destek Güveni**: Önerilen entegrasyon modeli
</Note>

TokenLab için Vercel AI SDK'daki en kararlı varsayılan **OpenAI uyumlu sağlayıcıdır (OpenAI-compatible provider)**.

Eğer özellikle **Responses-native** davranışına ihtiyaç duyuyorsanız, OpenAI sağlayıcısına geçiş yapabilir ve aynı TokenLab base URL'ini kullanmaya devam edebilirsiniz.

Bu sayfayı, Vercel AI SDK'daki her yardımcının TokenLab tarafından desteklendiğinin bir garantisi olarak değil, önerilen bir entegrasyon modeli olarak değerlendirin.

## TokenLab Sağlayıcı Paketi

TokenLab ayrıca Vercel AI SDK için hafif bir sağlayıcı sarmalayıcısı (wrapper) bulundurur:

```bash theme={null}
npm install ai @tokenlabai/ai-sdk-provider
```

```typescript theme={null}
import { generateText } from 'ai';
import { tokenlab } from '@tokenlabai/ai-sdk-provider';

const { text } = await generateText({
  model: tokenlab.chatModel('gpt-5.4'),
  prompt: 'Explain TokenLab in one sentence.',
});

console.log(text);
```

## Önerilen Varsayılan: OpenAI Uyumlu Sağlayıcı

```bash theme={null}
npm install ai @ai-sdk/openai-compatible
```

```typescript theme={null}
import { createOpenAICompatible } from '@ai-sdk/openai-compatible';

export const tokenlab = createOpenAICompatible({
  name: 'tokenlab',
  apiKey: process.env.TOKENLAB_API_KEY,
  baseURL: 'https://api.tokenlab.sh/v1',
});
```

## Metin Oluşturma (Generate Text)

```typescript theme={null}
import { generateText } from 'ai';
import { tokenlab } from './tokenlab';

const { text } = await generateText({
  model: tokenlab.chatModel('gpt-5.4'),
  prompt: 'Explain TokenLab in one sentence.',
});

console.log(text);
```

## Metin Akışı (Stream Text)

```typescript theme={null}
import { streamText } from 'ai';
import { tokenlab } from './tokenlab';

const result = await streamText({
  model: tokenlab.chatModel('gpt-5.4'),
  prompt: 'Write a short poem about coding.',
});

for await (const textPart of result.textStream) {
  process.stdout.write(textPart);
}
```

## Araç Çağırma (Tool Calling)

```typescript theme={null}
import { generateText, tool } from 'ai';
import { z } from 'zod';
import { tokenlab } from './tokenlab';

const result = await generateText({
  model: tokenlab.chatModel('gpt-5.4'),
  prompt: 'What is the weather in San Francisco?',
  tools: {
    weather: tool({
      description: 'Get weather in a location',
      parameters: z.object({
        location: z.string(),
      }),
      execute: async ({ location }) => ({
        location,
        temperature: 72,
        condition: 'sunny',
      }),
    }),
  },
});

console.log(result.text);
```

## Yapılandırılmış Çıktı (Structured Output)

```typescript theme={null}
import { generateObject } from 'ai';
import { z } from 'zod';
import { tokenlab } from './tokenlab';

const { object } = await generateObject({
  model: tokenlab.chatModel('gpt-5.4'),
  schema: z.object({
    name: z.string(),
    role: z.string(),
  }),
  prompt: 'Generate a fake developer profile.',
});

console.log(object);
```

## Eğer Açıkça Responses-Native Davranışına İhtiyacınız Varsa

```bash theme={null}
npm install ai @ai-sdk/openai
```

```typescript theme={null}
import { createOpenAI } from '@ai-sdk/openai';

export const tokenlabResponses = createOpenAI({
  apiKey: process.env.TOKENLAB_API_KEY,
  baseURL: 'https://api.tokenlab.sh/v1',
});
```

```typescript theme={null}
import { generateText } from 'ai';
import { tokenlabResponses } from './tokenlab-responses';

const { text } = await generateText({
  model: tokenlabResponses('gpt-5.4'),
  prompt: 'Explain TokenLab in one sentence.',
});
```

<Note>
  Proxy tarzı entegrasyonlar için güvenli varsayılan olarak `@ai-sdk/openai-compatible` kullanın. Yalnızca `/v1/responses` üzerine kurulu bir sağlayıcı yolunu açıkça istediğinizde `@ai-sdk/openai` paketine geçiş yapın.
</Note>

## Ortam Değişkenleri (Environment Variables)

```bash theme={null}
# .env.local
TOKENLAB_API_KEY=sk-your-tokenlab-key
```

## En İyi Uygulamalar

<AccordionGroup>
  <Accordion title="Öncelikle openai-compatible tercih edin">
    Üçüncü taraf ağ geçitleri ve proxy arka uçları için `@ai-sdk/openai-compatible` genellikle en sorunsuz başlangıç noktasıdır.
  </Accordion>

  <Accordion title="Yalnızca gerektiğinde Responses'a geçin">
    Eğer `/v1/responses` ile ilişkili bir sağlayıcı davranışına ihtiyacınız varsa, her iki modeli tek bir istemcide karıştırmak yerine sağlayıcı paketini bilinçli olarak değiştirin.
  </Accordion>

  <Accordion title="Gizli bilgileri sunucuda tutun">
    TokenLab API anahtarınızı asla istemci tarafındaki kodlarda açık etmeyin. Sağlayıcı kurulumunu sunucu dosyalarında veya API rotalarında yapın.
  </Accordion>
</AccordionGroup>
