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.
種類 : フレームワーク / プラットフォーム主要パス : OpenAI 互換 defaultサポートレベル : 推奨統合パターン
TokenLab では、Vercel AI SDK における最も安定した既定値は OpenAI互換プロバイダー です。
特に Responses-native の動作が必要な場合は、OpenAIプロバイダーに切り替えつつ、同じ TokenLab の base URL を維持できます。
このページは推奨される統合パターンとして参照してください。Vercel AI SDK のすべてのヘルパーに対して、このリポジトリで専用の end-to-end 回帰があることを意味するわけではありません。
推奨デフォルト: OpenAI互換プロバイダー
npm install ai @ai-sdk/openai-compatible
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' ,
});
テキスト生成
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 );
テキストストリーミング
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 );
}
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 );
構造化出力
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 );
明示的にResponses-Nativeの動作が必要な場合
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.4' ),
prompt: 'Explain TokenLab in one sentence.' ,
});
プロキシスタイルの統合では、安全なデフォルトとして @ai-sdk/openai-compatible を使用してください。/v1/responses 上に構築されたプロバイダーパスを明示的に使いたい場合にのみ、@ai-sdk/openai に切り替えてください。
環境変数
# .env.local
TOKENLAB_API_KEY = sk-your-tokenlab-key
ベストプラクティス
まず openai-compatible を優先する
サードパーティのゲートウェイやプロキシバックエンドでは、@ai-sdk/openai-compatible が通常、最も予測しやすい出発点です。
/v1/responses に紐づくプロバイダー動作が必要な場合は、1つの client で両方のパターンを混在させるのではなく、意図的にプロバイダーパッケージを切り替えてください。
TokenLab API key をクライアントサイドのコードに公開してはいけません。プロバイダーの設定はサーバーファイルまたは API routes に配置してください。