GuidesSDK Guides
SDK + Native SDK Coexistence
Run the CoreValue SDK alongside your existing OpenAI or Anthropic SDK — wrap only the calls you need.
SDK + Native SDK Coexistence
Four patterns for using CoreValue Gateway, from zero-friction to full FinOps metadata.
Tier: Available on all tiers. The @cova/gateway / cova-gateway SDK is free and open source.
Pattern 1: BaseURL Swap (No SDK)
Point your OpenAI SDK at the gateway. Get logging + billing, no FinOps metadata in response.
const client = new OpenAI({
apiKey: "sk-cova-...",
baseURL: "https://gateway.corevalue.dev/v1",
});See: Zero-Friction BaseURL Swap
Pattern 2: SDK wrap() (Non-Streaming FinOps)
Use @cova/gateway to parse Cova-* response headers into typed CovaResponse.
import OpenAI from "openai";
import { wrap, buildHeaders } from "@cova/gateway";
const client = new OpenAI({
apiKey: "sk-cova-...",
baseURL: "https://gateway.corevalue.dev/v1",
});
const response = await client.chat.completions.create({
model: "gpt-4o",
messages: [{ role: "user", content: "Hello" }],
extraHeaders: buildHeaders({ userId: "user_123" }),
});
const covaResponse = wrap(response, response.headers);
console.log(covaResponse.gateway.requestCost);
console.log(covaResponse.gateway.creditsRemaining);Pattern 3: Native SDK + fetchNative() (Native Format + FinOps)
Call a native-format endpoint (Anthropic, Google) and get FinOps metadata via headers.
import { fetchNative, buildHeaders } from "@cova/gateway";
const { response, gateway } = await fetchNative(
"https://gateway.corevalue.dev/v1/messages",
{
method: "POST",
headers: { "Authorization": "Bearer sk-cova-...", "Content-Type": "application/json" },
body: JSON.stringify({ model: "claude-3-5-sonnet", messages: [...] }),
cova: { userId: "user_123" },
}
);
console.log(gateway.requestCost);Pattern 4: SDK streamChat() (Streaming + FinOps)
Streaming with metadata via final SSE event after [DONE].
import OpenAI from "openai";
import { streamChat, buildHeaders } from "@cova/gateway";
const client = new OpenAI({ apiKey: "sk-cova-...", baseURL: "https://gateway.corevalue.dev/v1" });
for await (const chunk of streamChat(client, { model: "gpt-4o", messages: [...], stream: true })) {
if ("cova" in chunk) {
console.log(chunk.cova.requestCost);
} else {
process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
}
}Comparison
| Pattern | SDK Required | FinOps Metadata | Streaming | Native Format |
|---|---|---|---|---|
| 1. BaseURL swap | No | No | Yes | No |
2. wrap() | Yes | Yes (non-streaming) | No | No |
3. fetchNative() | Yes | Yes | No | Yes |
4. streamChat() | Yes | Yes (streaming) | Yes | No |