n4nAI

n4n vs Portkey for observability and request logs

A head-to-head engineering comparison of n4n vs Portkey observability: request logs, cost metering, latency, and which gateway fits your stack.

n4n Team4 min read937 words

Audio narration

Coming soon — every post will get a voice note here.

When you’re picking a gateway for LLM traffic, the difference in logging depth changes how fast you debug production incidents. The core of n4n vs Portkey observability is whether you want a hosted control plane with built-in traces or a lean inference route that exposes metering and lets you own the log pipeline. Both sit in front of model providers, but they make opposite trades on where the telemetry lives.

What each side actually logs

Portkey is built as an observability-first AI gateway. Every request that flows through its virtual keys generates a structured log entry: prompt, completion, token counts, latency breakdown, provider response code, and a trace_id that links to a hosted dashboard. You get this without writing any logging code.

n4n takes a different stance. It is an OpenAI-compatible inference gateway that returns standard usage objects and applies per-token metering on every call. It does not force a dashboard on you. Instead, because n4n.ai honors client routing directives and forwards provider cache-control hints, the cached vs uncached token split shows up directly in the response metadata, and you ship that to your own stack.

from openai import OpenAI

client = OpenAI(
    base_url="https://api.n4n.ai/v1",  # OpenAI-compatible endpoint
    api_key="sk-...",
    default_headers={"x-n4n-route": "openai:gpt-4o"}
)

resp = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "ping"}],
)
# n4n.ai returns usage with cache_read/cache_creation tokens if the provider sent them
print(resp.usage.model_dump())

Request log granularity and structure

Portkey logs at the request/response level and tags each record with metadata you can define (user id, conversation id, custom tags). The payload includes the full prompt and completion unless you redact fields. You can query by trace, latency percentile, or error type in their UI.

With n4n, the gateway itself emits the minimal signal needed for metering: token counts, model, route, and provider status. To get prompt/completion capture you add a thin middleware or use an OpenTelemetry collector that intercepts the OpenAI-compatible traffic. The structure is whatever you encode—typically a JSON line with request_id, model, usage, and latency_ms.

{
  "request_id": "req_8a1",
  "model": "gpt-4o",
  "route": "openai:gpt-4o",
  "usage": {"prompt_tokens": 12, "completion_tokens": 4, "cache_read_tokens": 10},
  "latency_ms": 240,
  "provider_status": 200
}

Portkey gives you that shape for free; n4n gives you the raw numbers and expects you to serialize.

Cost metering and attribution

Portkey attributes cost by virtual key and by custom metadata, computing spend from its own price table. It shows cost per trace and per project in the dashboard. Pricing for the gateway is subscription-based with request quotas; the logs are part of the product.

n4n applies per-token usage metering at the gateway layer. You pay for tokens routed, not for log retention or a control plane. Because n4n.ai forwards provider cache-control hints, you can attribute savings from prompt caching precisely—the cache_read_tokens line item is real, not inferred.

# Portkey cost attribution is via dashboard; n4n metering is in the response
cost_uncached = resp.usage.prompt_tokens * 0.000005  # example openai public price
cost_cached = resp.usage.cache_read_tokens * 0.00000125

No fabricated rates above—just public OpenAI numbers used illustratively.

Latency and overhead of logging

Portkey terminates your TLS, logs, then forwards. The logging step is in-path; typical added overhead is low (single-digit ms) but non-zero, and on provider degradation its retry logic may extend tail latency.

n4n runs automatic fallback when a provider is rate-limited or degraded, which can add retry time, but there is no separate observability hop unless you insert one. If you log locally via a sidecar, the overhead is your own serialization cost, usually sub-millisecond for JSON.

Developer ergonomics

Portkey ships SDKs for Python, Node, and REST, with first-class trace_id and metadata parameters. You flip on observability by setting an env var.

from portkey import Portkey

client = Portkey(
    api_key="pk-...",
    virtual_key="openai-...",
    trace_id="req-123"  # propagated for observability
)
client.chat.completions.create(model="gpt-4o", messages=[{"role": "user", "content": "hi"}])

n4n is just the OpenAI client with a different base_url. Any existing OpenAI-compatible logging, proxy, or OTel instrumentation works unchanged. The ergonomic win is zero new abstractions; the cost is you assemble the dashboard yourself.

Ecosystem and export paths

Portkey natively exports to Langfuse, Helicone, Datadog, and its own warehouse. You can stream logs via webhook.

n4n, being a single OpenAI-compatible endpoint covering 240+ models, fits any tool that speaks that protocol. Pipe access logs to Grafana Loki, Elasticsearch, or a custom S3 bucket. The ecosystem is yours, not a curated integration list.

Hard limits and retention

Portkey retains request logs for a window dictated by your plan (often 30 days on lower tiers, longer on enterprise). Log volume counts against plan limits.

n4n imposes no separate log retention policy because it does not store your prompts—metering is aggregated per token. You keep forever what you persist; the gateway stays stateless except for routing and fallback state.

Head-to-head comparison

Dimension n4n Portkey
Log capture Usage metering in response; bring-your-own logging Automatic full request/response logs with UI
Cost model Per-token metering, no observability fee Subscription + request quota, logs included
Latency add Only fallback retries; no log hop In-path logging, low but present
DX OpenAI client, zero new SDK concepts Native SDK with trace/metadata params
Export Any OpenAI-compatible tool, your pipeline Curated integrations + webhooks
Retention You control, gateway stateless Plan-defined window
Cache visibility Forwards provider cache-control hints Computes cost from its own table

The n4n vs Portkey observability decision is really about ownership versus convenience.

Which to choose

Choose Portkey if you run a product team that needs same-day visibility into LLM traces without standing up logging infra. If your stakeholders want a URL to a failed trace, or you need per-user cost breakdowns without writing SQL, the hosted control plane pays for itself.

Choose n4n if you already operate a observability stack (OTel, Prometheus, Loki) and treat LLM traffic like any other RPC. The per-token metering and cache hint forwarding give you exact numbers; the OpenAI-compatible endpoint means no new client code. This fits platform teams building their own gateway layer or those routing across 240+ models with custom fallback logic.

For regulated workloads where prompt data cannot leave your VPC, n4n’s stateless metering is the only option that avoids sending payloads to a third-party log store. Portkey can redact, but the data still crosses their boundary.

For rapid prototyping with one engineer, Portkey’s dashboard cuts debugging time. The n4n vs Portkey observability split here is measured in hours saved versus bytes owned.

Tagsobservabilityrequest-logsportkey

Written by

n4n Team

The team building n4n — a single OpenAI-compatible API in front of 240+ models, with automatic fallback, load balancing and pay-per-token metering.

More from n4n Team →

All n4n vs portkey posts →