Tokener CA
Service online
Sign up
DocsVercel AI SDK Integration

Vercel AI SDK Integration

Integrate Tokener CA using the OpenAI Compatible provider of the Vercel AI SDK.

Updated:

Use Cases

The Vercel AI SDK is a TypeScript toolkit for AI applications, commonly used in Next.js, React, Vue, Svelte, and Node.js projects. It provides an OpenAI Compatible provider that lets you integrate Tokener CA into generateText, streamText, tool calls, and chat interfaces.

The integration values are as follows:

SettingValue
package@ai-sdk/openai-compatible
baseURLhttps://a.skypool.xyz/v1
apiKeyConsumer API Key, for example stc-...
modelPlatform model name, for example gemma4:26b

Install Dependencies

Bash
pnpm add ai @ai-sdk/openai-compatible

npm:

Bash
npm install ai @ai-sdk/openai-compatible

Configure Environment Variables

Add the following to .env.local:

Bash
SKYPOOL_API_KEY=stc-...

Do not commit real API keys to the repository.

Non-Streaming Call

TypeScript
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";import { generateText } from "ai"; const skypool = createOpenAICompatible({  name: "skypool",  baseURL: "https://a.skypool.xyz/v1",  apiKey: process.env.SKYPOOL_API_KEY,}); const { text, usage, finishReason } = await generateText({  model: skypool.chatModel("gemma4:26b"),  prompt: "In one sentence, explain that the Vercel AI SDK is already integrated with Tokener CA.",  maxOutputTokens: 128,}); console.log(text);console.log(usage);console.log(finishReason);

If your AI SDK version supports calling the provider directly, you can also write the model as skypool("gemma4:26b"). To reduce version differences, the examples in this article use the explicit chatModel.

Streaming Call

TypeScript
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";import { streamText } from "ai"; const skypool = createOpenAICompatible({  name: "skypool",  baseURL: "https://a.skypool.xyz/v1",  apiKey: process.env.SKYPOOL_API_KEY,}); const result = streamText({  model: skypool.chatModel("gemma4:26b"),  prompt: "Introduce Tokener CA in three points.",  maxOutputTokens: 512,}); for await (const textPart of result.textStream) {  process.stdout.write(textPart);}

Next.js Route Handler Example

TypeScript
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";import { streamText } from "ai"; const skypool = createOpenAICompatible({  name: "skypool",  baseURL: "https://a.skypool.xyz/v1",  apiKey: process.env.SKYPOOL_API_KEY,}); export async function POST(request: Request) {  const { messages } = await request.json();   const result = streamText({    model: skypool.chatModel("gemma4:26b"),    messages,    maxOutputTokens: 1024,  });   return result.toUIMessageStreamResponse();}

Tool Call Recommendations

The Vercel AI SDK converts tool definitions into model call parameters. When using Tokener CA, we recommend first validating a minimal tool with a model that supports tool calls, and then integrating it into complex workflows.

If you run into structured output or tool call parameter incompatibilities, first confirm:

  • Whether the target model supports tool calls
  • Whether the request goes through https://a.skypool.xyz/v1/chat/completions
  • Whether you are sending provider-specific parameters that the model does not support

Verify with curl First

Bash
curl -X POST "https://a.skypool.xyz/v1/chat/completions" \  -H "Authorization: Bearer <consumer_api_key>" \  -H "Content-Type: application/json" \  --data-raw '{    "model": "gemma4:26b",    "messages": [      {        "role": "user",        "content": "Return a short message confirming the integration succeeded."      }    ],    "max_tokens": 64,    "stream": false  }'

Troubleshooting Checklist

SymptomHow to handle
Environment variable is emptyMake sure SKYPOOL_API_KEY is set in .env.local, and restart the dev server
401Check whether the Consumer API Key is valid
404Check whether baseURL is https://a.skypool.xyz/v1 and whether the model ID is correct
No output from the streaming endpointVerify with the non-streaming generateText first, then switch to streamText
Tool call failsSwitch to a model that supports tool calls, and reduce provider-specific parameters

References