@workstudio/ai
v1.0.1
Published
Unified interface for AI agents supporting OpenAI, Gemini, Anthropic, and xAI with multimodal and tool-calling support.
Maintainers
Readme
@workstudio/ai
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.
Features
- 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.
Installation
pnpm add @workstudio/ai
# or
npm install @workstudio/aiQuick Start
Basic Text Prompt
import { 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);Multimodal (Image + Text)
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);Tool Calling
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
}Supported Providers
| 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 |
Contributing
Please see CONTRIBUTING.md for details on how to get involved.
License
MIT © Workstudio
