Portkey supports xAI’s chat completions, completions, and embeddings APIs.
Integrate
Just paste your xAI API Key to Portkey to create your Virtual Key.
Sample Request
Portkey is a drop-in replacement for xAI. You can make request using the official Portkey SDK.
Popular libraries & agent frameworks like LangChain, CrewAI, AutoGen, etc. are also supported.
Local Setup
If you do not want to use Portkey’s hosted API, you can also run Portkey locally:
Open Source (npm or docker)
Open Source (npm or docker)
Portkey runs on our popular open source Gateway. You can spin it up locally to make requests without sending them to the Portkey API.
Your Gateway is running on http://localhost:8080/v1 🚀 |
---|
Then, just change the baseURL
to the local Gateway URL, and make requests:
On-Prem Deployment (AWS, GCP, Azure)
On-Prem Deployment (AWS, GCP, Azure)
Portkey’s data & control planes can be fully deployed on-prem with the Enterprise license.
Integration Overview
xAI Endpoints & Capabilities
Portkey works with all of xAI’s endpoints and supports all xAI capabilities like function calling and image understanding. Find examples for each below:
Tool Calling (Function Calling)
Tool Calling (Function Calling)
Vision
Vision
Process images alongside text using xAI’s vision capabilities:
Embeddings
Embeddings
Generate embeddings for text using xAI’s embedding models:
Coming Soon!
Portkey Features
Setup Fallbacks & Loadbalancer
Setup Fallbacks & Loadbalancer
Here’s a simplified version of how to use Portkey’s Gateway Configuration:
Create a Gateway Configuration
You can create a Gateway configuration using the Portkey Config Dashboard or by writing a JSON configuration in your code. In this example, requests are routed based on the user’s subscription plan (paid or free).
Process Requests
When a user makes a request, it will pass through Portkey’s AI Gateway. Based on the configuration, the Gateway routes the request according to the user’s metadata.
Set Up the Portkey Client
Pass the Gateway configuration to your Portkey client. You can either use the config object or the Config ID from Portkey’s hosted version.
That’s it! Portkey seamlessly allows you to make your AI app more robust using built-in gateway features. Learn more about advanced gateway features:
Load Balancing
Distribute requests across multiple targets based on defined weights.
Fallbacks
Automatically switch to backup targets if the primary target fails.
Conditional Routing
Route requests to different targets based on specified conditions.
Caching
Enable caching of responses to improve performance and reduce costs.
Setup Guardrails
Setup Guardrails
Portkey’s AI gateway enables you to enforce input/output checks on requests by applying custom hooks before and after processing. Protect your user’s/company’s data by using PII guardrails and many more available on Portkey Guardrails:
Learn More About Guardrails
Explore Portkey’s guardrail features to enhance the security and reliability of your AI applications.
Appendix
FAQs
How to get the xAI API key?
How to get the xAI API key?
You can sign up to xAI here and grab your API key.
Is is free to use the xAI API key?
Is is free to use the xAI API key?
xAI typically gives some amount of free credits without you having to add your credit card. Reach out to their support team if you’d like additional free credits.
I am getting rate limited on xAI API
I am getting rate limited on xAI API
You can find your current rate limits imposed by xAI on the console. Use Portkey’s loadbalancer to tackle rate limiting by xAI.