artificial-gateway-sdk
v1.1.26
Published
Multi-provider AI gateway SDK — unified API for OpenAI, Anthropic, Google, xAI, DeepSeek, Mistral, and more. Chat, images, audio, embeddings, and files.
Maintainers
Readme
Artificial Gateway SDK
Universal AI gateway client for OpenAI, Anthropic, Google AI, xAI (Grok), DeepSeek, Mistral, Qwen, Stability AI, ElevenLabs, and more.
Single SDK, any model, any provider. The gateway handles routing, fallback, and billing transparently.
npm install artificial-gatewayQuick Start
import { ArtificialGateway } from "artificial-gateway";
const client = new ArtificialGateway({
apiKey: "ag_your_key_here",
// baseUrl: "https://your-deployment.com", // optional
});
// Works with any provider — just pick a model
const completion = await client.chat.completions.create({
model: "gpt-5.4",
messages: [{ role: "user", content: "Hello!" }],
});Chat Completions (All Providers)
Works with OpenAI, Anthropic, Google, xAI, DeepSeek, Mistral, Qwen, and more.
// Non-streaming
const reply = await client.chat.completions.create({
model: "claude-sonnet-4-6",
messages: [{ role: "user", content: "Explain quantum computing" }],
max_tokens: 1000,
});
console.log(reply.choices[0].message.content);
// Streaming
const stream = await client.chat.completions.create({
model: "gpt-5.4",
messages: [{ role: "user", content: "Write a poem" }],
stream: true,
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
}Multimodal (Vision + Audio)
// Image understanding (GPT-4o, Claude, Gemini, Grok, Mistral, Qwen)
const reply = await client.chat.completions.create({
model: "gemini-2.5-pro",
messages: [{
role: "user",
content: [
{ type: "text", text: "What's in this image?" },
{ type: "image_url", image_url: { url: "https://example.com/photo.jpg" } },
],
}],
});
// Audio in chat (Gemini, GPT-4o audio)
const reply = await client.chat.completions.create({
model: "gpt-5.4",
messages: [{
role: "user",
content: [
{ type: "text", text: "Transcribe this:" },
{ type: "input_audio", input_audio: { data: base64audio, format: "wav" } },
],
}],
});Tool / Function Calling
const reply = await client.chat.completions.create({
model: "gpt-5.4",
messages: [{ role: "user", content: "What's the weather in Tokyo?" }],
tools: [{
type: "function",
function: {
name: "get_weather",
description: "Get current weather",
parameters: {
type: "object",
properties: {
location: { type: "string" },
},
required: ["location"],
},
},
}],
tool_choice: "auto",
});Structured Output
const reply = await client.chat.completions.create({
model: "gpt-5.4",
messages: [{ role: "user", content: "Extract: John is 30" }],
response_format: {
type: "json_schema",
json_schema: {
name: "person",
strict: true,
schema: {
type: "object",
properties: {
name: { type: "string" },
age: { type: "number" },
},
required: ["name", "age"],
additionalProperties: false,
},
},
},
});Images
Works with OpenAI (DALL-E 3/2) and Stability AI (through the gateway).
// Generate
const images = await client.images.generate({
model: "dall-e-3",
prompt: "A cosmic turtle flying through space",
n: 1,
size: "1024x1024",
});
console.log(images.data[0].url);
// Edit (add mask to change part of image)
const edit = await client.images.edit({
image: imageFile,
mask: maskFile,
prompt: "Add a castle in the background",
});
// Variations
const variations = await client.images.createVariation({
image: imageFile,
n: 3,
});Audio
Works with OpenAI Whisper (STT), Google (STT), OpenAI TTS, and ElevenLabs (through the gateway).
// Speech-to-text (transcription)
const transcript = await client.audio.transcriptions.create({
file: audioFile,
model: "whisper-1",
language: "en",
});
console.log(transcript.text);
// Translation (transcribe + translate to English)
const translation = await client.audio.translations.create({
file: audioFile,
model: "whisper-1",
});
// Text-to-speech
const audioResponse = await client.audio.speech.create({
model: "tts-1",
input: "Hello, this is a test of the text to speech system.",
voice: "alloy",
response_format: "mp3",
});
const blob = await audioResponse.blob();
// Save or stream the audio blobEmbeddings
Works with OpenAI, Google, Mistral, and other embedding providers.
const embedding = await client.embeddings.create({
model: "text-embedding-3-small",
input: "The quick brown fox jumps over the lazy dog",
});
console.log(embedding.data[0].embedding); // number[]
// Batch embedding
const batch = await client.embeddings.create({
model: "text-embedding-3-small",
input: ["Hello world", "Goodbye world"],
});Files
// Upload
const file = await client.files.create({
file: fileObject,
purpose: "assistants",
});
// List
const files = await client.files.list();
// Retrieve
const info = await client.files.retrieve("file-xxx");
// Delete
await client.files.del("file-xxx");
// Download content
const content = await client.files.retrieveContent("file-xxx");Moderations
const result = await client.moderations.create({
input: "I want to hurt someone",
});
console.log(result.results[0].flagged); // true/falseModels
const models = await client.models.list();
console.log(models.map(m => `${m.id} (${m.owned_by})`));Provider Examples
The Artificial Gateway routes by model name. The same SDK works with all providers:
| Model | Provider | Capabilities |
|---|---|---|
| gpt-5.4 | OpenAI | chat, vision, tools, streaming, reasoning |
| claude-sonnet-4-6 | Anthropic | chat, vision, tools, streaming |
| gemini-2.5-pro | Google | chat, vision, audio, tools, streaming |
| grok-4.3 | xAI | chat, vision, tools, streaming |
| deepseek-v4-flash | DeepSeek | chat, tools, reasoning |
| mistral-large-3 | Mistral | chat, vision, tools |
| qwen3.7-max | Qwen | chat, vision, tools, reasoning |
| dall-e-3 | OpenAI | image generation |
| whisper-1 | OpenAI | audio STT |
| tts-1 | OpenAI | audio TTS |
| text-embedding-3-small | OpenAI | embeddings |
Error Handling
import { ArtificialGateway, ArtificialGatewayError } from "artificial-gateway";
try {
await client.chat.completions.create({ ... });
} catch (err) {
if (err instanceof ArtificialGatewayError) {
console.error(`[${err.status}] ${err.message}`);
}
}API Reference
ArtificialGateway(config)
| Option | Type | Default | Description |
|---|---|---|---|
| apiKey | string | required | Your ag_... API key |
| baseUrl | string | https://app.artificialguy.com | Gateway deployment URL |
Namespaces
| Namespace | Methods | Description |
|---|---|---|
| chat.completions | create() | Chat completions (stream + non-stream) |
| images | generate(), edit(), createVariation() | Image generation, editing, variations |
| audio.transcriptions | create() | Speech-to-text |
| audio.translations | create() | Audio translation to English |
| audio.speech | create() | Text-to-speech |
| embeddings | create() | Text embeddings |
| models | list() | Available models |
| files | create(), list(), retrieve(), del(), retrieveContent() | File management |
| moderations | create() | Content moderation |
Requirements
- Node.js 18+ (or modern browser with
fetch,FormData,ReadableStream) - TypeScript (for type definitions)
License
MIT
