Enterprise Feature
gRPC support is available on Enterprise self-hosted plans only. Contact the Portkey team to enable it for your gateway deployment.
gRPC support is available on Enterprise self-hosted plans only. Contact the Portkey team to enable it for your gateway deployment.
gRPC support is currently in beta. The API surface may change based on feedback.
How It Works
The gateway operates in two modes depending on the provider:
For providers without a native gRPC endpoint, the gateway transparently proxies gRPC requests over HTTP — so every provider supported by Portkey works out of the box. When a provider does expose a native gRPC API (currently Google Gemini), the gateway connects directly for optimal performance.
Starting the gRPC Server
Command Line Flags
Environment Variables
Enabling TLS
The gRPC server supports TLS using the same certificates as the HTTP server:Authentication
Pass your Portkey API key as gRPC metadata:
With the Model Catalog, the provider is specified in the model string itself (
@provider_slug/model_name), so separate provider headers are typically not needed.
Making Requests
All request bodies are sent as a JSON string in theinput field of the GatewayRequest message. Each endpoint returns responses in a consistent format matching the API you called, regardless of the underlying provider:
- ChatCompletions and Embeddings — OpenAI-compatible format
- Messages — Anthropic Messages format
- Responses — OpenAI Responses API format
Model String Format
Portkey uses the Model Catalog format for model strings:@openai/gpt-4o, @gemini/gemini-2.0-flash, @anthropic/claude-3-opus-20240229, @azure-openai/gpt-4
Chat Completions
- grpcurl
- Python (grpcio)
- Node.js (@grpc/grpc-js)
Anthropic Messages
- grpcurl
- grpcurl (Streaming)
OpenAI Responses
- grpcurl
- grpcurl (Streaming)
Embeddings
Health Check
Native gRPC Providers
When a provider exposes a native gRPC API, the gateway bypasses HTTP entirely and makes direct gRPC calls for the lowest possible latency.How Native gRPC Works
When a request targets a native gRPC provider, the gateway:- Detects the gRPC transport via the
x-portkey-gateway-transport: grpcheader - Transforms the request into the provider’s native gRPC format
- Makes a direct gRPC call to the provider’s endpoint
- Transforms the response back to the format matching the endpoint you called
- Gemini (Non-Streaming)
- Gemini (Streaming)
gRPC Service Definition
The gateway exposes a singleGateway service with the following methods:
Message Types
Service Discovery
The gRPC server supports reflection, enabling service discovery with tools likegrpcurl:
Response Format
TheGatewayResponse contains an HTTP status code and a JSON body. The response format depends on which endpoint you called — the gateway ensures consistency regardless of the underlying provider.
ChatCompletions
Returns the standard OpenAI Chat Completions format:- Non-Streaming
- Streaming
Messages (Anthropic)
Returns the Anthropic Messages format — even when the underlying provider is not Anthropic (e.g., callingMessages with @openai/gpt-4o):
Responses (OpenAI Responses API)
Returns the OpenAI Responses API format:Response Metadata
HTTP response headers are returned as gRPC trailing metadata:Error Handling
Provider and request errors are returned inside theGatewayResponse.status_code field, not as gRPC status codes on the wire. The gRPC call itself will return OK unless there is a gateway infrastructure failure (e.g., server crash, proto parse error).
Use the table below to interpret the status_code value in the response:
Always check
GatewayResponse.status_code to detect errors — do not rely on the gRPC call status alone.When to Use gRPC vs HTTP
Connection Management
The gateway maintains a cache of gRPC client connections:- Connections are reused per API key for efficiency
- Stale connections are automatically cleaned up
- Default timeout: 60 seconds (300 seconds for streaming)
Limitations
- WebSocket-based realtime endpoints (
/v1/realtime) are not available via gRPC - File upload/download operations use HTTP proxy mode only
- Batch operations use HTTP proxy mode only
- Only server-side streaming is supported (no bidirectional streaming)
Troubleshooting
Connection Refused
--llm-grpc flag:
Authentication Errors
INVALID_ARGUMENT Errors
input field. Ensure the model string follows the @provider_slug/model_name format.
Timeout Issues
For long-running requests, increase the client-side timeout:- Python
- Node.js

