Provider Slug
x-ai

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.

import Portkey from 'portkey-ai';

const client = new Portkey({
  apiKey: 'PORTKEY_API_KEY',
  virtualKey: 'PROVIDER_VIRTUAL_KEY'
});

async function main() {
  const response = await client.chat.completions.create({
    messages: [{ role: "user", content: "Bob the builder.." }],
    model: "grok-beta",
  });

  console.log(response.choices[0].message.content);
}

main();

Local Setup

If you do not want to use Portkey’s hosted API, you can also run Portkey locally:


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:

Portkey Features


Appendix

FAQs