Skip to content
Go To Dashboard

AI Model Access

Access 400+ AI models through a single API — GPT-4, Claude, Gemini, Llama, and more — without managing separate accounts or API keys.

import { withSapiom } from "@sapiom/axios";
import axios from "axios";
const client = withSapiom(axios.create(), {
apiKey: process.env.SAPIOM_API_KEY,
});
const { data } = await client.post(
"https://openrouter.services.sapiom.ai/v1/chat/completions",
{
model: "openai/gpt-4o-mini",
messages: [{ role: "user", content: "Hello, world!" }],
max_tokens: 100,
}
);
console.log(data.choices[0].message.content);

Sapiom routes requests through OpenRouter, which provides unified access to AI models from all major providers. The SDK handles payment negotiation automatically — you pay per token based on the model you use.

The API is OpenAI-compatible, so you can use familiar patterns:

  • Standard chat completions format
  • System, user, and assistant message roles
  • Temperature, top_p, and other generation parameters
  • Function/tool calling (on supported models)
  • JSON mode for structured outputs

You authorize a maximum cost based on max_tokens, but only pay for actual tokens generated.

Powered by OpenRouter. OpenRouter aggregates 400+ models from OpenAI, Anthropic, Google, Meta, Mistral, and others.

Endpoint: POST https://openrouter.services.sapiom.ai/v1/chat/completions

Create a chat completion using any supported model.

ParameterTypeRequiredDescription
modelstringYesFull model name with provider (e.g., openai/gpt-4o-mini)
messagesarrayYesArray of message objects with role and content
max_tokensnumberYesMaximum tokens to generate (required for cost calculation)
temperaturenumberNoSampling temperature (0-2)
top_pnumberNoNucleus sampling (0-1)
frequency_penaltynumberNoFrequency penalty (-2 to 2)
presence_penaltynumberNoPresence penalty (-2 to 2)
stopstring[]NoStop sequences
toolsarrayNoTool definitions for function calling
response_formatobjectNo{ "type": "json_object" } for JSON mode
{
"model": "openai/gpt-4o-mini",
"messages": [
{ "role": "system", "content": "You are a helpful assistant." },
{ "role": "user", "content": "What is TypeScript?" }
],
"max_tokens": 500,
"temperature": 0.7
}
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1700000000,
"model": "openai/gpt-4o-mini",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "TypeScript is a strongly typed programming language..."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 25,
"completion_tokens": 150,
"total_tokens": 175
}
}

Endpoint: POST https://openrouter.services.sapiom.ai/v1/chat/completions/price

Get a price estimate without executing the request.

const { data } = await client.post(
"https://openrouter.services.sapiom.ai/v1/chat/completions/price",
{
model: "openai/gpt-4o-mini",
messages: [{ role: "user", content: "Hello!" }],
max_tokens: 100,
}
);
console.log(`Maximum cost: ${data.price}`);

Response:

{
"price": "$0.000025",
"currency": "USD",
"model": "openai/gpt-4o-mini",
"estimatedInputTokens": 10,
"maxOutputTokens": 100,
"scheme": "upto"
}

OpenRouter provides access to 400+ models. Here are some popular options:

ProviderModels
OpenAIopenai/gpt-4o, openai/gpt-4o-mini, openai/gpt-4-turbo
Anthropicanthropic/claude-3.5-sonnet, anthropic/claude-3-opus
Googlegoogle/gemini-pro, google/gemini-flash
Metameta-llama/llama-3.1-405b, meta-llama/llama-3.2-90b
Mistralmistralai/mistral-large, mistralai/mixtral-8x7b

See the OpenRouter Models page for the full list and pricing.

import { withSapiom } from "@sapiom/axios";
import axios from "axios";
const client = withSapiom(axios.create(), {
apiKey: process.env.SAPIOM_API_KEY,
});
const baseUrl = "https://openrouter.services.sapiom.ai/v1";
async function chat(userMessage: string) {
const { data } = await client.post(`${baseUrl}/chat/completions`, {
model: "openai/gpt-4o-mini",
messages: [
{ role: "system", content: "You are a helpful assistant." },
{ role: "user", content: userMessage },
],
max_tokens: 500,
temperature: 0.7,
});
return data.choices[0].message.content;
}
// Usage
const response = await chat("Explain quantum computing in simple terms");
console.log(response);
CodeDescription
400Invalid request — check model name and parameters
402Payment required — ensure you’re using the Sapiom SDK
404Model not found — use full model name with provider prefix
429Rate limit exceeded

Missing max_tokens: The gateway requires max_tokens to calculate maximum cost:

// Wrong — missing max_tokens
{ model: "openai/gpt-4o-mini", messages: [...] }
// Correct
{ model: "openai/gpt-4o-mini", messages: [...], max_tokens: 100 }

Model not found: Use the full model name with provider prefix:

// Wrong
{ model: "gpt-4o-mini" }
// Correct
{ model: "openai/gpt-4o-mini" }

Pricing varies by model and is based on token usage:

  • Input tokens: Cost per 1M tokens (varies by model)
  • Output tokens: Cost per 1M tokens (varies by model)

The gateway uses an “upto” payment scheme — you authorize maximum cost based on max_tokens, but only pay for tokens actually generated.

See OpenRouter Pricing for per-model rates.