A unified, type-safe interface for building agentic AI applications. Support for OpenAI, Google Gemini, Anthropic Claude, and xAI Grok with a single, consistent API.
- Unified API: Switch between providers (OpenAI, Gemini, Anthropic, xAI) with minimal code changes.
- Multimodal Support: Easily handle text and image inputs (base64) across all supported models.
- Tool Calling: Standardized interface for function/tool calling for agentic workflows.
- JSON Schema Enforcement: Native support for structured outputs using JSON schemas.
- TypeScript First: Full type safety for messages, data parts, and provider configurations.
pnpm add @workstudio/ai
# or
npm install @workstudio/aiimport { OpenAIProvider } from "@workstudio/ai";
const ai = new OpenAIProvider("gpt-4o");
const messages = [
{ role: "user", parts: [{ text: "Hello, how are you?" }] }
];
const struct = {
instructions: ["You are a helpful assistant."],
context: [],
responseSchema: {
type: "object",
properties: {
reply: { type: "string" }
},
required: ["reply"]
}
};
const response = await ai.prompt(messages, struct);
console.log(response.reply);import { GeminiProvider } from "@workstudio/ai";
const ai = new GeminiProvider(process.env.GEMINI_API_KEY);
const messages = [
{
role: "user",
parts: [
{ text: "What is in this image?" },
{
inlineData: {
data: "base64_encoded_image_data",
mimeType: "image/jpeg"
}
}
]
}
];
const response = await ai.prompt(messages, {
instructions: [],
context: [],
responseSchema: null
});
console.log(response.message);const struct = {
instructions: ["Help the user with weather and time."],
context: [],
responseSchema: null,
tools: [
{
name: "get_weather",
description: "Get current weather for a location",
parameters: {
type: "object",
properties: {
location: { type: "string" }
},
required: ["location"]
}
}
]
};
const response = await ai.prompt(messages, struct);
if (response.tool_calls) {
// Handle tool calling
}| Provider | Class | Default Model |
|---|---|---|
| OpenAI | OpenAIProvider |
gpt-4o |
| Gemini | GeminiProvider |
gemini-2.0-flash |
| Anthropic | AnthropicProvider |
claude-3-5-sonnet-latest |
| xAI | XAIProvider |
grok-2-1218 |
Please see CONTRIBUTING.md for details on how to get involved.
MIT © Workstudio