Skip to content

Type to search the docs and the model list.

Vercel AI SDK

Use eWest models with generateText, streamText, tools and embed.

The AI SDK reaches eWest through its OpenAI-compatible provider, so generateText, streamText, tools, embed and the UI hooks work with every ewest/* chat and embedding model. Examples are plain JavaScript and need Node 22 or newer (the AI SDK packages require it); they work unchanged in TypeScript and in Next.js route handlers.

Setup

Install the AI SDK, the OpenAI-compatible provider and zod (for tool inputs):

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

Create an API key and put it in the EWEST_KEY environment variable (export EWEST_KEY=sk-…). The examples read it from there; never put the key in browser code.

Create the provider once with the base URL https://api.ewest.ai/v1 and your key. includeUsage asks for token counts on streamed responses as well.

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

const ewest = createOpenAICompatible({
  name: "ewest",
  baseURL: "https://api.ewest.ai/v1",
  apiKey: process.env.EWEST_KEY,
  includeUsage: true, // token usage on streamed responses too
});

export default ewest;

Already using the OpenAI or Anthropic provider? Both work with eWest too: set baseURL to https://api.ewest.ai/v1 in either. With @ai-sdk/openai, ewest.chat(id) sends chat completions and ewest(id) uses the Responses API.

import { createOpenAI } from "@ai-sdk/openai";
import { generateText } from "ai";

const ewest = createOpenAI({ baseURL: "https://api.ewest.ai/v1", apiKey: process.env.EWEST_KEY });

// ewest.chat() uses /v1/chat/completions; ewest() uses /v1/responses.
const { text } = await generateText({
  model: ewest.chat("ewest/claude-haiku"),
  prompt: "Say hello in one short sentence.",
  maxOutputTokens: 256,
});
console.log(text);

Choose a model

Use the full model ID, including the ewest/ prefix. The table has good starting points; Models lists every model with its context window and limits, and GET /v1/models returns the models your key may use. Chat models go in ewest(id), embedding models in ewest.embeddingModel(id).

Use, Model ID
UseModel ID
Fast and cheap chat, toolsewest/claude-haiku
Stronger reasoning and codingewest/claude-sonnet
Long context (1M tokens), images, audio and video inputewest/gemini-flash
Embeddings for search and RAGewest/gemini-embedding

Verify it works

A first request with generateText. It prints the answer and the token usage.

import { generateText } from "ai";
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";

const ewest = createOpenAICompatible({
  name: "ewest",
  baseURL: "https://api.ewest.ai/v1",
  apiKey: process.env.EWEST_KEY,
  includeUsage: true, // token usage on streamed responses too
});

const { text, usage } = await generateText({
  model: ewest("ewest/claude-haiku"),
  prompt: "Say hello in one short sentence.",
  maxOutputTokens: 256,
});
console.log(text);
console.log(usage);

The request shows up in the console under Requests within a few seconds, with its tokens and cost. Every response carries an x-request-id header, its trace ID.

Streaming and tools

streamText returns text as it is generated. Read textStream in Node, or return result.toUIMessageStreamResponse() from a Next.js route for useChat.

import { streamText } from "ai";
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";

const ewest = createOpenAICompatible({
  name: "ewest",
  baseURL: "https://api.ewest.ai/v1",
  apiKey: process.env.EWEST_KEY,
  includeUsage: true, // token usage on streamed responses too
});

const result = streamText({
  model: ewest("ewest/claude-haiku"),
  prompt: "Write a haiku about the sea.",
  maxOutputTokens: 256,
});
for await (const text of result.textStream) process.stdout.write(text);
console.log("\n", await result.usage);

Tools are defined with a zod schema and an execute function. With stopWhen, the SDK sends the tool result back to the model so it can answer in the same call.

import { generateText, stepCountIs, tool } from "ai";
import { z } from "zod";
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";

const ewest = createOpenAICompatible({
  name: "ewest",
  baseURL: "https://api.ewest.ai/v1",
  apiKey: process.env.EWEST_KEY,
  includeUsage: true, // token usage on streamed responses too
});

const { text, steps } = await generateText({
  model: ewest("ewest/claude-haiku"),
  tools: {
    getWeather: tool({
      description: "Get the current weather for a city",
      inputSchema: z.object({ city: z.string() }),
      execute: async ({ city }) => ({ city, temperatureC: 18, sky: "cloudy" }),
    }),
  },
  stopWhen: stepCountIs(3), // call the tool, then answer with its result
  prompt: "What is the weather in Yerevan?",
  maxOutputTokens: 256,
});
console.log(steps.flatMap((s) => s.toolCalls.map((c) => c.toolName)));
console.log(text);

Embeddings use embed (one value) or embedMany (a list) with an embedding model:

import { embed } from "ai";
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";

const ewest = createOpenAICompatible({
  name: "ewest",
  baseURL: "https://api.ewest.ai/v1",
  apiKey: process.env.EWEST_KEY,
  includeUsage: true, // token usage on streamed responses too
});

const { embedding } = await embed({
  model: ewest.embeddingModel("ewest/gemini-embedding"),
  value: "How do I reset my password?",
});
console.log(embedding.length);

Troubleshooting

  • 404 `model_not_found`: the model name needs the ewest/ prefix (ewest/claude-haiku, not claude-haiku). Check the spelling against Models.
  • Empty answer from `ewest/gemini-flash`: ewest/gemini-flash does not think unless reasoning is on (low, medium or high); then thinking uses output tokens and a small output limit can be used up. Allow at least 256 output tokens, or turn reasoning off (below). This is a known limitation.
  • Follow-up turns forget the conversation: on the Responses API, pass the earlier response's id as previous_response_id (conversations are stored by default), or send the full message history with every request; chat completions and Messages are always stateless. See Responses.
  • 401, 402 or 403: the key is missing or wrong, out of budget, or not allowed to use this model. Errors explains each code; a trace ID finds the request in the console.
  • No usage on streamed responses: set includeUsage: true on the provider.

Turning reasoning off: pass reasoningEffort: "none" in providerOptions, under the provider's name. Most chat models accept none; a few don't (their lowest is low) and answer 400 unsupported_value. Check the model's reasoning_efforts in GET /v1/models/{id} or the catalog.

import { generateText } from "ai";
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";

const ewest = createOpenAICompatible({
  name: "ewest",
  baseURL: "https://api.ewest.ai/v1",
  apiKey: process.env.EWEST_KEY,
  includeUsage: true, // token usage on streamed responses too
});

const { text } = await generateText({
  model: ewest("ewest/gemini-flash"),
  prompt: "Say hello in one short sentence.",
  maxOutputTokens: 256,
  providerOptions: { ewest: { reasoningEffort: "none" } }, // answer without thinking first
});
console.log(text);

Still stuck? Follow Troubleshoot a request.