Framework'ler ve platformlar

Vercel AI SDK

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

Genel Bakış

Tür: Framework veya Platform

Birincil Yol: OpenAI uyumlu varsayılan

Destek Güveni: Önerilen entegrasyon modeli

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:

npm install ai @tokenlabai/ai-sdk-provider
import { generateText } from 'ai';
import { tokenlab } from '@tokenlabai/ai-sdk-provider';

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

console.log(text);

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

npm install ai @ai-sdk/openai-compatible zod
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)

import { generateText } from 'ai';
import { tokenlab } from './tokenlab';

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

console.log(text);

Metin Akışı (Stream Text)

import { streamText } from 'ai';
import { tokenlab } from './tokenlab';

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

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

Araç Çağırma (Tool Calling)

import { generateText, stepCountIs, tool } from 'ai';
import { z } from 'zod';
import { tokenlab } from './tokenlab';

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

console.log(result.text);

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

import { generateObject } from 'ai';
import { z } from 'zod';
import { tokenlab } from './tokenlab';

const { object } = await generateObject({
  model: tokenlab.chatModel('gpt-5.6-terra'),
  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

npm install ai @ai-sdk/openai
import { createOpenAI } from '@ai-sdk/openai';

export const tokenlabResponses = createOpenAI({
  apiKey: process.env.TOKENLAB_API_KEY,
  baseURL: 'https://api.tokenlab.sh/v1',
});
import { generateText } from 'ai';
import { tokenlabResponses } from './tokenlab-responses';

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

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.

Ortam Değişkenleri (Environment Variables)

# .env.local
TOKENLAB_API_KEY=sk-your-tokenlab-key

En İyi Uygulamalar

Bu sayfada