canonical: https://jentic.com/apis/portkey.ai/portkey

# Portkey AI Gateway

Portkey AI Gateway provides a unified OpenAI-compatible interface to access over 250 AI models from multiple providers through a single API. It supports chat completions, text completions, embeddings, and image generation with built-in caching, observability, and load balancing. Authentication uses a Portkey API key in the x-portkey-api-key header combined with a virtual key to identify the target AI provider.

## For AI agents

Route chat completions, text completions, embeddings, and image generation requests to 250+ AI models through a single unified gateway endpoint.

## Scope

Does not handle model fine-tuning, dataset management, or agent orchestration - use for inference routing only.

## Capabilities

- Route chat completion requests to any of 250+ AI models with provider-agnostic parameters
- Generate text embeddings from multiple embedding model providers through one endpoint
- Create images from text prompts via supported generation models
- Switch between AI providers without changing client code by swapping virtual keys
- Stream partial chat completion responses via server-sent events for real-time output

## Use cases

### Multi-Provider Model Routing

Route AI inference requests to different providers (OpenAI, Anthropic, Cohere, and others) through a single API endpoint. Portkey handles provider-specific authentication and response format normalization, allowing teams to switch models by changing a virtual key rather than rewriting integration code. Supports fallback routing when a primary provider experiences downtime.

Example prompt: Send a chat completion request to GPT-4 through Portkey with messages containing a system prompt and user query, then verify the response includes token usage data

### Embedding Generation for RAG Pipelines

Generate vector embeddings from text inputs for retrieval-augmented generation workflows. The embeddings endpoint accepts single strings or batches and returns float or base64-encoded vectors. Teams can switch embedding providers without modifying downstream vector storage logic.

Example prompt: Create embeddings for the text 'quarterly revenue report summary' using the text-embedding-3-small model and return the vector in float format

### Streaming Chat for Interactive Applications

Enable real-time conversational interfaces by streaming partial chat completion tokens as server-sent events. The gateway handles streaming uniformly across providers, so client code receives a consistent SSE format regardless of which backend model generates the response.

Example prompt: Send a streaming chat completion request with stream set to true and process the partial message deltas as they arrive

### AI Agent Gateway Integration via Jentic

AI agents use Jentic to discover Portkey Gateway operations by intent, such as 'generate a chat completion' or 'create text embeddings'. Jentic returns the operation schema with required parameters (model, messages) and handles Portkey API key injection, so agents call AI models without managing provider credentials directly.

Example prompt: Search Jentic for 'generate a chat completion', load the Portkey createChatCompletion schema, and execute a request with model gpt-4 and a user message

## Key endpoints

| Method | Path | Description |
| --- | --- | --- |
| POST | `/chat/completions` | Create a chat completion from a conversation |
| POST | `/completions` | Generate text completions from a prompt |
| POST | `/embeddings` | Create vector embeddings from text input |
| POST | `/images/generations` | Generate images from text prompts |

## Key resources

- **Inference** — Chat completions, text completions, embeddings, and image generation routed through the unified gateway

## Why Jentic

- **Setup:** Wiring the Portkey AI Gateway by hand means managing its x-portkey-api-key header, wiring a virtual key for each provider, and formatting inference requests yourself. Through Jentic you install once, import the Portkey AI Gateway from the API Directory, store the key once, and your agent calls it.
- **Permission scoping:** Portkey takes its prompts and model inputs in the request body, so you limit the agent to the operations it needs, such as chat completions or embeddings. Other operations like image generation are available only if you add them.
- **Credential handling:** Your Portkey API key and virtual keys are stored once, encrypted, by your own Jentic One instance and injected at execution time. They never enter the agent's prompt, logs, or context.
- **Discovery method:** Agents search Jentic by intent such as 'generate a chat completion' or 'create embeddings', and Jentic returns the matching Portkey operation with its input schema so the agent calls the right endpoint without browsing the reference docs.

## Related APIs

- **OpenAI API** — Direct access to OpenAI models without gateway routing
- **OpenRouter API** — Another multi-model routing gateway with pay-per-token pricing
- **Cohere API** — Enterprise NLP and embedding models accessible directly or through Portkey

## FAQ

### What authentication does the Portkey AI Gateway use?

Portkey uses two API keys passed as headers: x-portkey-api-key for your Portkey account authentication, and x-portkey-virtual-key to identify the target AI provider. Through Jentic, both keys are stored in the encrypted credential vault and injected automatically.

### Can I route requests to different AI providers without changing my code?

Yes. The Portkey AI Gateway uses a virtual key system. You change the x-portkey-virtual-key header to switch between providers like OpenAI, Anthropic, or Cohere while keeping the same endpoint and request format. The chat completions, completions, and embeddings endpoints accept the same parameters regardless of the backend provider.

### What are the rate limits for the Portkey AI Gateway?

Rate limits depend on your Portkey plan tier and the underlying AI provider's limits. The gateway passes through provider-specific rate limit headers. Check your Portkey dashboard for account-level limits and the target provider's documentation for model-specific constraints.

### How do I generate embeddings through the Portkey AI Gateway with Jentic?

Install the SDK with pip install jentic, then search for 'create text embeddings'. Jentic returns the createEmbedding operation schema requiring model and input fields. Execute the call with your text input and receive embedding vectors in float or base64 format.

### Does the Portkey AI Gateway support streaming responses?

Yes. Set the stream parameter to true in your chat completion or text completion request. The gateway returns partial message deltas as server-sent events in a consistent format, regardless of which backend AI provider generates the response.

### Can I use function calling and tool use through the Portkey AI Gateway?

Yes. The chat completions endpoint supports the tools parameter for defining function schemas and tool_choice for controlling tool selection. The gateway passes tool calls and tool responses through to the underlying model, supporting up to 128 tool definitions per request.

### Can I limit what my agent is allowed to do with the Portkey AI Gateway?

Yes. Because you run Jentic One yourself, your own rules decide which Portkey operations and credentials the agent may use. You can allow only the inference calls it needs, such as chat completions or embeddings, and leave text completions or image generation unimported so the agent cannot reach them. Since prompts and model inputs travel in the request body, scoping the agent to a single operation like chat completions keeps it from touching any endpoint you have not granted.
