TypeScript providers
Wrap OpenAI, Azure OpenAI, Cohere, Anthropic, Gemini, Bedrock, Deepgram, ElevenLabs, and Realtime with @superpenguin/js.
OpenAI
OpenRouter can use the OpenAI-compatible wrapper described below or OpenRouter Broadcast. Avoid enabling both for the same calls unless a shared generation ID makes exact deduplication possible.
import OpenAI from "openai";
import { wrap } from "@superpenguin/js";
const openai = wrap(new OpenAI());
await openai.chat.completions.create({
model: "gpt-4o",
messages: [{ role: "user", content: "Hello!" }],
spMetadata: { customer_id: "cust_123" },
});Supported: chat.completions.create, completions.create, embeddings.create, responses.create, including streams that report usage.
Azure OpenAI
Wrap AzureOpenAI (or an OpenAI client pointed at an Azure endpoint). SuperPenguin detects Azure from the host (*.openai.azure.com, *.services.ai.azure.com, and related Azure AI hosts). There is no separate Azure wrapper.
Azure region is not auto-captured. Typical Azure hosts use a resource name, not a region, so pass wrap-level region and deploymentType if you want SDK estimates to use the matching rate card. Omit both for Global Standard (the default).
import { AzureOpenAI } from "openai";
import { wrap } from "@superpenguin/js";
const openai = wrap(
new AzureOpenAI({
endpoint: "https://my-resource.openai.azure.com",
apiKey: "...",
apiVersion: "2024-10-21",
}),
{
region: "eastus2",
deploymentType: "regional",
},
);| Deployment | What to pass |
|---|---|
| Global Standard | omit region and deploymentType |
| Data Zone | deploymentType: "data-zone" |
| Regional | region (location code, e.g. eastus2) and deploymentType: "regional" |
region must be the Azure location code from the portal / ARM (eastus2, westeurope, swedencentral). Case does not matter (EastUS2 works). Display names (East US 2) and AWS-style ids (us-east-2) will not match, so the estimate falls back to Global. For deploymentType, use exactly "regional" or "data-zone" (keep the hyphen). Passing only region is not enough for regional rates. Connecting Azure for billed spend already uses invoice amounts; these fields only affect SDK estimates. See Batch and service-tier pricing.
Cohere
Cohere support is available in JavaScript SDK 0.11.0 and later. Upgrade
@superpenguin/js before using the examples below.
Wrap CohereClientV2 from the optional cohere-ai dependency (version 8.1
or later in the 8.x series).
Compatible APIs and models
The following model and API combinations have been verified. Other model IDs
are not covered by this list. Model availability depends on your provider
account and, for Bedrock, AWS region. The Bedrock combinations below were
verified in us-west-2.
| API | Operation | Verified model |
|---|---|---|
| Cohere native | Text Embed | embed-v5.0-fast |
| Cohere native | Rerank | rerank-v4.0-fast |
| Cohere native | Chat, including streaming | command-r7b-12-2024 |
| Cohere OpenAI-compatible | Text Embed | embed-v5.0-pro |
| Cohere OpenAI-compatible | Chat, including streaming | command-r7b-12-2024 |
| AWS Bedrock InvokeModel | Text Embed | cohere.embed-english-v3 |
| AWS Bedrock InvokeModel or Agent Runtime | Rerank | cohere.rerank-v3-5:0 |
For AWS Bedrock, wrap an AWS SDK v3 client and use promise-based send.
Native Cohere example
Native Embed accepts inputType to distinguish search documents from queries.
Replace the API key placeholders with your own keys.
import { CohereClientV2 } from "cohere-ai";
import { init, wrap, flush } from "@superpenguin/js";
init({ apiKey: "YOUR_SUPERPENGUIN_KEY" });
const cohere = wrap(new CohereClientV2({ token: "YOUR_COHERE_KEY" }));
await cohere.embed({
model: "embed-v5.0-fast",
texts: ["A small penguin."],
inputType: "search_document",
embeddingTypes: ["float"],
});
await flush();OpenAI-compatible example
Wrap an OpenAI client using Cohere's compatibility URL and a Cohere API key.
Omit input_type for this endpoint.
import OpenAI from "openai";
import { init, wrap, flush } from "@superpenguin/js";
init({ apiKey: "YOUR_SUPERPENGUIN_KEY" });
const cohere = wrap(new OpenAI({
apiKey: "YOUR_COHERE_KEY",
baseURL: "https://api.cohere.ai/compatibility/v1",
}));
await cohere.embeddings.create({
model: "embed-v5.0-pro",
input: ["A small penguin."],
encoding_format: "float",
});
await flush();Usage and cost
SuperPenguin uses the provider's reported input/output tokens for Chat, input tokens for Embed, and billed search units for native Rerank. Cost also requires a matching price for the model and API. Missing usage or pricing leaves cost unknown; it does not mean the request was free.
Bedrock Rerank requests are tracked, but responses without billed search units have unknown per-request cost. SuperPenguin does not estimate search units from the number of documents or results. The AWS Agent Runtime Rerank response does not include billed usage. Connecting AWS billing can supply aggregate billed spend, but does not fill in these individual request costs.
Consume Chat streams fully to receive their final usage. A stream that ends before usage arrives can leave usage and cost unknown. Usage telemetry does not include document bodies or embedding vectors.
Not supported
- Rerank through Cohere's OpenAI-compatible endpoint. Use the native Cohere client for Rerank.
input_typeon OpenAI-compatible Embed requests. Cohere's endpoint rejects this parameter, including when sent through the OpenAI SDK's extra request body options. Omit it, or use native Embed to specify search documents or queries. See Cohere's supported parameters.- Usage tracking for batch jobs, image or multimodal Embed, Parse, Transcribe and SageMaker. These operations and deployment paths are outside this integration's coverage.
- Usage tracking for AWS callback-style
send. Use promise-basedsendwith a wrapped AWS SDK v3 client.
Retired Bedrock Chat models
The Bedrock models cohere.command-r-v1:0 and cohere.command-r-plus-v1:0
reached end of life on August 19, 2026.
Use direct Cohere Chat with a model from the compatibility table above.
Doubleword
Wrap an OpenAI client pointed at https://api.doubleword.ai/v1. SuperPenguin attributes the billed route as doubleword (the model maker stays in model_vendor). Scope custom prices to doubleword.
Anthropic
import Anthropic from "@anthropic-ai/sdk";
import { wrap } from "@superpenguin/js";
const anthropic = wrap(new Anthropic());
await anthropic.messages.create({
model: "claude-sonnet-4-20250514",
max_tokens: 1024,
messages: [{ role: "user", content: "Hello!" }],
spMetadata: { customer_id: "cust_123" },
});Google Gemini
import { GoogleGenAI } from "@google/genai";
import { wrap } from "@superpenguin/js";
const genai = wrap(new GoogleGenAI({ apiKey: "..." }));
await genai.models.generateContent({
model: "gemini-2.5-pro",
contents: "Hello!",
});Deepgram
import { createClient } from "@deepgram/sdk";
import { wrap } from "@superpenguin/js";
const dg = wrap(createClient("..."), {
metadata: { customer_id: "cust_123" },
deepgramTier: "growth",
});ElevenLabs
import { ElevenLabsClient } from "@elevenlabs/elevenlabs-js";
import { wrap } from "@superpenguin/js";
const el = wrap(new ElevenLabsClient({ apiKey: "..." }), {
metadata: { customer_id: "cust_123" },
});AWS Bedrock
import {
BedrockRuntimeClient,
ConverseCommand,
} from "@aws-sdk/client-bedrock-runtime";
import { wrap } from "@superpenguin/js";
const bedrock = wrap(
new BedrockRuntimeClient({ region: "us-west-2" }),
{
metadata: { customer_id: "cust_123", feature: "doc_summary" },
deploymentType: "global",
},
);
await bedrock.send(
new ConverseCommand({
modelId: "anthropic.claude-3-5-sonnet-20241022-v2:0",
messages: [{ role: "user", content: [{ text: "Hello!" }] }],
}),
);Usage is sent with cost_usd_micros: 0; the server prices with the live aws_bedrock catalog. Region is auto-captured.
OpenAI Realtime
import { OpenAIRealtimeWebSocket } from "openai/beta/realtime/websocket";
import { wrapRealtime } from "@superpenguin/js";
const rt = new OpenAIRealtimeWebSocket({ model: "gpt-realtime" });
wrapRealtime(rt, { metadata: { feature: "voice-agent" } });For raw WebSocket / WebRTC consumers, use trackRealtimeEvent(event, { model: "gpt-realtime" }).
Provider-specific helpers
import {
wrapOpenAI,
wrapAnthropic,
wrapGoogleGenAI,
wrapDeepgram,
wrapElevenLabs,
wrapBedrock,
wrapRealtime,
trackRealtimeEvent,
} from "@superpenguin/js";