Providers
Collection of predefined providers.
This package is not recommended for xsAI-based libraries, which can increase the size of the installation.
npm i @xsai-ext/providersUsage
Predefined
It reads the API Key from the environment variables via
process.env, so it cannot be used in a browser.
import { google } from '@xsai-ext/providers'
import { generateText } from '@xsai/generate-text'
import { env } from 'node:process'
const { text } = await generateText({
...google.chat('gemini-2.5-flash'),
apiKey: env.GEMINI_API_KEY!,
baseURL: 'https://generativelanguage.googleapis.com/v1beta/openai/',
messages: [{
content: 'Why is the sky blue?',
role: 'user'
}],
model: 'gemini-2.5-flash',
})Create
You can also import a create function instead of a predefined provider, making it runtime-agnostic:
// import { google } from '@xsai-ext/providers'
import { createGoogleGenerativeAI } from '@xsai-ext/providers/create'
import { generateText } from '@xsai/generate-text'
const google = createGoogleGenerativeAI('YOUR_API_KEY_HERE')
const { text } = await generateText({
...google.chat('gemini-2.5-flash'),
messages: [{
content: 'Why is the sky blue?',
role: 'user'
}],
})Deprecated
Please migrate to the Providers package as soon as possible. The legacy packages will be officially deprecated in v0.4.0.
Cloud
npm i @xsai-ext/providers-cloudExamples
Keys
Checkout all supported providers here.
import * as providers from '@xsai-ext/providers-cloud'
type Keys = keyof typeof providersOpenAI
import { createOpenAI } from '@xsai-ext/providers-cloud'
import { generateText } from '@xsai/generate-text'
import { env } from 'node:process'
const openai = createOpenAI(env.OPENAI_API_KEY!)
const { text } = await generateText({
...openai.chat('gpt-4o'),
apiKey: env.OPENAI_API_KEY!,
baseURL: 'https://api.openai.com/v1/',
messages: [{
content: 'Why is the sky blue?',
role: 'user'
}],
model: 'gpt-4o',
})Local
npm i @xsai-ext/providers-localExamples
Keys
Checkout all supported providers here.
import * as providers from '@xsai-ext/providers-local'
type Keys = keyof typeof providersOllama
import { createOllama } from '@xsai-ext/providers-local'
import { generateText } from '@xsai/generate-text'
import { env } from 'node:process'
const ollama = createOllama()
const { text } = await generateText({
...ollama.chat('llama3.2'),
baseURL: 'http://localhost:11434/v1/',
messages: [{
content: 'Why is the sky blue?',
role: 'user'
}],
model: 'llama3.2',
})