2027 integration guide · Evidence checked 20 November 2026

Vercel AI SDK with Plugsky: exact provider setup

The Vercel AI SDK ships an OpenAI-compatible provider for endpoints that speak the Chat Completions shape. Plugsky is one of those endpoints, so the integration is a package, a provider instance and a model ID. This guide gives the exact configuration, text and streaming code, embeddings, typed error handling and the limits that remain after the first request works.

Short answer. Install ai and @ai-sdk/openai-compatible, then call createOpenAICompatible with name: 'plugsky', baseURL: 'https://api.plugsky.com/v1', your Plugsky key and includeUsage: true. Pass plugsky('plugsky-frontier') to generateText or streamText. The SDK appends the endpoint path, so the base URL must not include /chat/completions.

What the OpenAI-compatible provider does

The AI SDK separates the model interface from the transport. generateText, streamText, generateObject and embed call a provider object; the provider builds the HTTP request. The @ai-sdk/openai-compatible package implements that provider for services that expose OpenAI-style Chat Completions, including third-party gateways and self-hosted servers.

Plugsky implements the Chat Completions surface at https://api.plugsky.com/v1. That makes the compatible provider the correct choice, not the OpenAI provider. The OpenAI provider is configured for OpenAI’s host and product surface; pointing it at another host is a workaround, while the compatible provider is designed for exactly this case.

The provider is a client-side abstraction, not a gateway. It does not add retries across providers, normalise model names, cache responses or enforce a budget. Those are application or gateway concerns. If you need central routing and policy, put them in front of the SDK rather than inside every route handler.

Install and configure the provider

Install the SDK and the compatible provider package. Pin versions in your lockfile; the provider’s option set changes between major releases.

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

Create one provider instance per process and reuse it. The name is not cosmetic: it becomes the key for providerOptions and for provider metadata, so keep it stable.

TypeScript
import { createOpenAICompatible } from '@ai-sdk/openai-compatible';

export const plugsky = createOpenAICompatible({
  name: 'plugsky',
  apiKey: process.env.PLUGSKY_API_KEY!,
  baseURL: 'https://api.plugsky.com/v1',
  includeUsage: true,
});
createOpenAICompatible settings for Plugsky
SettingValueWhy it matters
nameplugskyKeys provider options and metadata. Keep it identical across environments.
baseURLhttps://api.plugsky.com/v1Include /v1. No trailing slash, no /chat/completions.
apiKeyYour Plugsky keyThe SDK adds Authorization: Bearer <key>. Keep it in a server-only environment variable.
includeUsagetrueAsk for usage in streaming metadata when the provider returns it.
headersOmittedNo extra header is required for Plugsky. Add none unless your account documentation says otherwise.
queryParamsOmittedPlugsky does not require an API-version query parameter.
supportsStructuredOutputsOff until testedA flag is not a guarantee; strict schema support is model- and provider-dependent.
supportsMultiPartToolContentOffOnly enable if the provider accepts content arrays in tool results.

Host note. This guide uses https://api.plugsky.com/v1, the approved API host. Plugsky’s public documentation also shows https://plugsky.com/v1 in examples. Both hosts answered GET /v1/models on 20 November 2026, but they are different hostnames. Pick one and keep it in every environment.

Generate text

Start with a non-streamed call. It is easier to inspect the response, the finish reason and the usage block than a stream.

TypeScript
import { generateText } from 'ai';
import { plugsky } from './plugsky';

const { text, finishReason, usage } = await generateText({
  model: plugsky('plugsky-frontier'),
  instructions: 'You answer in two sentences and state uncertainty.',
  prompt: 'What is an OpenAI-compatible API?',
  maxOutputTokens: 256,
});

console.log({ text, finishReason, usage });

maxOutputTokens is a plan and model ceiling, not a target. Builder and Scale allow up to 32K output; Hobby allows 8K and Starter 16K. If the answer is truncated, check finishReason before you raise the limit: a length finish means the cap was reached, while a stop finish means the model chose to end. The current documentation calls the system prompt instructions; older major versions used system, so pin the major version and keep the name that version documents.

Stream text in a route handler

Streaming is the default shape for a chat product. This Next.js route handler keeps the key on the server and returns a plain text stream.

TypeScript
import { streamText } from 'ai';
import { plugsky } from '@/lib/plugsky';

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

  const result = streamText({
    model: plugsky('plugsky-frontier'),
    instructions: 'You are a concise product support assistant.',
    messages,
    maxOutputTokens: 1024,
  });

  return new Response(result.textStream, {
    headers: { 'Content-Type': 'text/plain; charset=utf-8' },
  });
}

result.textStream is a ReadableStream, so a plain text response needs no extra helper. For useChat, use the UI message stream response helper documented for your installed major version, because that helper’s name has changed between releases. Either way, test the stream end to end: a successful non-streamed call does not prove that your runtime, proxy or CDN forwards server-sent events without buffering.

Tool calling and structured output

The compatible provider passes tool definitions in the OpenAI shape, and the AI SDK can run a multi-step tool loop. Plugsky accepts the standard tools schema, but reliability varies by model and by conversation length. Test one tool with a trivial schema before you connect a database or a code runner, and keep a maximum step count so a loop cannot run unbounded.

Structured output needs more caution. The provider exposes a supportsStructuredOutputs flag, but turning it on only tells the SDK to send a schema; it does not make the model enforce it. Leave the flag off until a test with your chosen model returns valid objects on repeated runs. When you do enable it, keep validation and a retry path, because a schema violation is a data error, not a transport error. Tool calling and strict structured output are both test-first items with this endpoint.

Embeddings

The same provider instance exposes embeddingModel. Plugsky publishes three embedding IDs and returns 2,048-dimension vectors with an 8,192-token input limit.

TypeScript
import { embed } from 'ai';
import { plugsky } from './plugsky';

const { embedding } = await embed({
  model: plugsky.embeddingModel('plugsky-embed'),
  value: 'The quick brown fox jumps over the lazy dog.',
});

console.log(embedding.length); // 2048

Create the vector index at 2,048 dimensions before the first write. If your existing store expects 1,536 dimensions, either create a new index or use a different embedding model; do not truncate a vector to fit. Keep one embedding model per index, because vectors from different models are not comparable.

Typed errors and what to do with them

The AI SDK exposes typed errors rather than requiring you to match message strings. APICallError covers a failed provider request or non-success response; RetryError means the SDK’s retries were exhausted; StreamProviderError means the provider reported an error after the stream started.

TypeScript
import { APICallError, generateText } from 'ai';
import { plugsky } from './plugsky';

try {
  await generateText({
    model: plugsky('plugsky-frontier'),
    prompt: 'Reply with the single word ready.',
  });
} catch (error) {
  if (APICallError.isInstance(error)) {
    console.error('Provider status:', error.statusCode);
    return;
  }
  throw error;
}
Common AI SDK and Plugsky errors, likely cause and the first fix
Error or statusLikely causeFirst fix
401 via APICallErrorMissing, revoked or wrong-host keyCheck PLUGSKY_API_KEY in the server runtime, then confirm the base URL points at api.plugsky.com.
403Key scope or plan does not include the surfaceCheck the key role and the plan; use a key from the account that owns the model access.
404Base URL includes /chat/completions, or model ID is unknownSet baseURL to https://api.plugsky.com/v1 and use an ID from GET /v1/models.
400Malformed messages, unsupported parameter or context overflowRemove OpenAI-only parameters; trim history or lower maxOutputTokens when token counts are reported.
413Request body too largeReduce the prompt, chunk the document or send fewer messages.
429RPM, concurrency or daily quota exhaustedHonour Retry-After, add jitter and reduce parallel requests or tool steps.
500–503Server or upstream failure, possibly during failoverRetry with backoff; check status before changing code.
LoadAPIKeyErrorThe provider could not resolve the keyPass apiKey explicitly or set the environment variable in the runtime that executes the route.
NoObjectGeneratedErrorStructured output failed to parse or validateTurn off strict structured output, fix the schema, or add validation and a retry.

Limits that remain after the first request

  • The model ID must be exact. plugsky-frontier, plugsky-coder and plugsky-embed are IDs; gpt-4o is not served. Fetch the list from GET /v1/models and keep the mapping in configuration.
  • Plan ceilings beat model windows. Hobby allows 64K input and 8K output, Starter 128K and 16K, Builder 256K and 32K, and Scale a 512K plan input ceiling with 32K output. Most text models advertise 262,144 tokens; the plan limit still applies.
  • Concurrency is per account. Hobby allows 4 concurrent requests at 120 RPM, Starter 6 at 240 RPM, Builder 10 at 600 RPM and Scale 16 at 1,200 RPM. Serverless functions can fan out faster than the account limit.
  • Daily caps remain on the lower plans. Hobby is limited to 1,000 requests and 2M tokens per day; Starter to 2,000 requests and 5M tokens per day.
  • The SDK does not add provider fallback. If you want a second provider or a retry across models, build it explicitly or use a gateway. createOpenAICompatible is a single-provider client.
  • Streaming usage is conditional. includeUsage: true asks for usage metadata, but not every stream or provider returns it. Use a non-streamed call when the number must be exact.
  • Not every OpenAI surface exists. Chat, streaming, tool calling, JSON mode and embeddings are the relevant surfaces. Image generation, audio transcription, hosted file search and the Assistants product surface are outside the 39-model catalogue.
  • Prompt caching is not published. Do not plan savings from cached input until the API documents a cache contract.

What we did not verify

  • We did not run this provider against Plugsky end to end. The code follows the official AI SDK OpenAI-compatible provider documentation and error reference checked on 20 November 2026; package behaviour can change between major versions.
  • We did not test tool calling, multi-step loops, structured output, image input or streaming usage through Plugsky with this SDK. Those are marked “test first”.
  • We did not test every deployment runtime, edge runtime, proxy or CDN. Server-sent events can be buffered by infrastructure that is outside the SDK’s control.
  • We did not verify that includeUsage produces a usage block on every Plugsky stream; the option is documented by the AI SDK, not guaranteed by this endpoint.
  • We did not review a SOC 2 report, penetration test or subprocessor list. Request the current report under NDA and confirm the audit period and scope before you rely on it.

Frequently asked questions

Which package connects the Vercel AI SDK to Plugsky?

Use @ai-sdk/openai-compatible and its createOpenAICompatible function. It targets any provider that implements the OpenAI Chat Completions API, so you set the base URL to https://api.plugsky.com/v1, supply a Plugsky key and pass a Plugsky model ID. You do not need a Plugsky-specific SDK package.

What baseURL should createOpenAICompatible use?

Set baseURL to https://api.plugsky.com/v1, including /v1 and without a trailing slash. The AI SDK appends the endpoint path itself, so do not include /chat/completions. Plugsky's public docs also show https://plugsky.com/v1; both answered on 20 November 2026, but pick one and keep it across environments.

How do I get token usage from a streaming response?

Set includeUsage to true when you create the provider. The AI SDK then includes usage information in the response metadata for streaming requests when the provider returns it. Do not assume that every stream includes usage, and do not estimate billing from client-side token counts.

Does structured output work through the AI SDK?

The OpenAI-compatible provider can pass a JSON schema when supportsStructuredOutputs is enabled, but strict schema enforcement is a provider capability, not an AI SDK guarantee. Leave the flag off and test one schema against your chosen Plugsky model before you rely on generateObject in production.

Can I generate embeddings with the same provider?

Yes. Create the same provider instance and call embeddingModel with plugsky-embed, plugsky-embed-nim or plugsky-embed-multilingual. Each returns a 2,048-dimension vector and accepts up to 8,192 input tokens. Create the vector index at 2,048 dimensions before the first write, because changing it later requires a reindex.

Why does the AI SDK throw APICallError?

APICallError means the provider request failed or returned a non-success response. Read its statusCode and response body: 401 points to the key, 404 to the base URL or model ID, 400 to the request body or context length, and 429 to rate limits or quota. Fix the upstream cause before adding retries.

Next step

Run generateText once, then streamText, then tools and embeddings in that order. The host and parameter changes are collected at /docs/migrate/openai-api; the OpenAI-compatible API reference lists the supported surface, and /models is the authoritative model list. If you need routing, budgets or policy in front of several providers, read the AI gateway overview.

Ship the first request today

Start on the free plan with two keys, then move to a paid plan when concurrency and context ceilings matter.

Start Free → See pricing

Sources

Every provider claim below was checked on the linked official page on 20 November 2026. The AI SDK changes between major versions; recheck the provider options before you pin a production version.

Last checked 20 November 2026. Plugsky plan numbers live at /pricing; this page explains the integration and does not replace the plan terms.