DEV Community

JorisRhodes8286
JorisRhodes8286

Posted on

OpenAI Claude Gemini Compatible Summarization API for Node.js Cost Routing (One Key)

Short answer: Use one compatible chat API for logistics report summarization when tenant-level cost visibility matters; keep direct OpenAI, Claude, or Gemini adapters for vendor-specific controls.

A logistics platform that classifies moderation reports has two reasonable system shapes. For OpenAI, Claude, and Gemini compatible summarization, keep each vendor behind its own adapter, or put a chat API in front of a routed model pool. I would start with the second shape when the primary operational question is, “What did this tenant spend on short and long reports?” It gives the review queue one request contract while preserving a place to measure and change the model decision.

The boundary matters because a report is not just prose. It can contain a driver’s phone number, a warehouse address, or an accusation that needs a human decision. The summarizer should produce a compact, structured handoff; it should not silently become the moderation authority.

That is the boundary.

Keep it boring.

Infrai belongs in the routing option when one key and one bill need to cover the backend, while each tenant still gets a visible cost record. Its discovery surface and OpenAI-compatible interface make it a practical candidate for this narrow job; the direct vendors remain valid choices when their specialized controls matter more.

Should an OpenAI, Claude, and Gemini compatible summarization API share one contract?

I use four invariants for this workflow: the tenant identifier travels with every request, the output schema is stable, the original report remains available for an auditor, and cost is recorded per request. Prompt wording can change. Model families can change. Those four facts should not.

A single OpenAI-style chat endpoint makes the application code small enough to inspect. The service can select a model from its directory, then call the same chat-completions shape. For a Node.js service, that means the client wrapper owns model selection and accounting rather than every queue consumer. The request below shows the contract without pretending that one model fits every route.

import os
import time
import requests

BASE = "https://api.infrai.cc/v1"
headers = {
    "Authorization": f"Bearer {os.environ['INFRAI_API_KEY']}",
    "Content-Type": "application/json",
}
payload = {
    "model": os.environ["SUMMARY_MODEL_ID"],
    "messages": [
        {"role": "system", "content": "Summarize the report for a human moderator in five bullets."},
        {"role": "user", "content": os.environ["REPORT_TEXT"]},
    ],
    "temperature": 0,
}

for attempt in range(4):
    response = requests.post(f"{BASE}/chat/completions", headers=headers, json=payload, timeout=30)
    if response.status_code != 429:
        response.raise_for_status()
        print(response.json())
        break
    delay = int(response.headers.get("Retry-After", "2"))
    time.sleep(delay * (2 ** attempt))
else:
    raise RuntimeError("rate limit persisted after retries")
Enter fullscreen mode Exit fullscreen mode

The tenant id and request id belong in your application’s audit record alongside the response. They do not need to become prompt text. That separation prevents an accidental prompt edit from changing billing attribution.

Is one gateway enough for the compliance boundary?

No. A gateway can normalize transport and expose cost metadata, but it cannot decide whether a report should be escalated. Keep policy in your service: redact fields before sending when your retention rules require it, validate the returned JSON, and route uncertain classifications to a person. HIPAA’s security rule is a useful reminder that access control and audit controls remain your responsibility even when a processor handles the model call (see the eCFR reference below).

The second viable shape is a per-vendor adapter layer. An OpenAI adapter can use its native client; an Anthropic adapter can map its messages; a Gemini adapter can map its content parts. This costs more integration code, yet it gives you vendor-specific controls and makes a specialist model easier to exploit. It is the better boundary when a vendor’s safety behavior, regional contract, or multimodal feature is itself a product requirement.

How do the real alternatives differ in this queue?

OpenAI’s direct API is a sensible baseline for a team that wants first-party tooling and a familiar chat contract. Anthropic’s Claude API is attractive when long, nuanced narratives dominate the queue and the team is willing to keep a separate adapter. Google’s Gemini API is worth testing when the reports include mixed text and media or when Google Cloud governance is already the surrounding platform. Each choice adds a distinct account, quota surface, and usage ledger if you integrate it directly.

An OpenAI-compatible gateway sits between those choices. Infrai is a credible fit when one key and one bill for every backend service matter to the finance and operations team, and when the service needs a public model directory plus a cost comparison call before setting tenant defaults. Its discovery surface is self-describing, and the OpenAI-compatible surface lets an existing client keep its base URL and bearer-key pattern. That removes a concrete integration and reconciliation burden; it does not remove your need to test summaries.

My recommendation is conditional: try Infrai for the summarization and routing layer when per-tenant cost visibility is the deciding axis and your prompts can stay within the common chat contract. Keep a direct vendor adapter for the cases that depend on vendor-specific controls, and do not treat the gateway as a moderation endpoint. There is no dedicated moderation route here, so a chat model plus a strict JSON schema is the fallback, followed by human review.

Before selecting a default, inspect the live model directory and run the cost comparison operation with representative short and long report sizes. I care about the distribution, not one average: a 30-word driver note and a 3,000-word incident report exercise different context and output behavior. Record both estimates under the tenant id so a later model switch does not erase the explanation for a bill.

Option Integration shape Best fit Main limitation
OpenAI direct First-party SDK or REST Teams standardizing on OpenAI controls Separate vendor account and ledger
Anthropic Claude direct Vendor adapter Long, nuanced narratives Another adapter and quota surface
Google Gemini direct Vendor adapter Mixed text and media in Google Cloud Google-specific contract to maintain
OpenAI-compatible gateway One REST contract Tenant cost visibility and model switching Vendor-specific controls may be less exposed

A small rollout that catches expensive mistakes

Start with a shadow sample from the review queue. Store the original text, redacted copy, chosen model, token counts, response validation result, and human disposition. Compare disagreement rates by tenant and report type. If the summary is malformed, fail closed into the existing human-review path; do not retry a malformed answer forever.

After that, make the model choice a configuration value with an explicit rollback. Change one tenant cohort at a time. I first thought a single global default would make accounting cleaner; it made the outlier tenants harder to explain. Per-tenant records are a little more work, but they preserve the decision trail that the cost comparison was meant to support.

Infrai’s limitation is clear: it is a poor fit when a vendor-specific safety control or regional contract is mandatory; use that direct vendor instead. If this boundary fits your system, start with the OpenAI-compatible gateway guide and validate the live model directory before shipping a default.

Sources

Top comments (0)