Setting Up xAI as a Custom Provider
To use Grok models in PromptLayer:- Navigate to Settings → Custom Providers and Models in your PromptLayer dashboard
- Click Create Custom Provider
- Configure the provider with the following details:
- Name: xAI (or your preferred name)
- Client: OpenAI
- Base URL:
https://api.x.ai/v1 - API Key: Your xAI API key (get one at x.ai)
xAI uses OpenAI-compatible endpoints, which is why we select OpenAI as the client type.
Creating Custom Models (Recommended)
For easier model selection in the Playground and Prompt Registry, you can create custom models:- In Settings → Custom Providers and Models, find your xAI provider in the list
- Click on the xAI row to expand it
- Click Create Custom Model
- Configure each model:
- Provider: Select the xAI provider you created
- Model Name: Enter the Grok model identifier (e.g.,
grok-4-fast-reasoning,grok-3) - Display Name: A friendly name like “Grok 2” or “Grok Beta”
- Model Type: Chat
- Repeat for each model you want to use
Available Models
xAI regularly updates their model offerings. Example models include:grok-4-fast-reasoning: Latest Grok 4 with fast reasoning (2M context)grok-4-fast-non-reasoning: Grok 4 optimized for speed (2M context)grok-code-fast-1: Specialized for code generation tasksgrok-3: Grok 3 with advanced reasoning capabilitiesgrok-2-vision-1212: Grok 2 with vision capabilities
Using Grok in PromptLayer
In the Playground
After setup, you can use Grok models in the PromptLayer Playground:- Open the Playground
- Select your xAI provider from the provider dropdown
- Choose your desired Grok model
- Start querying with your prompts
In the Prompt Registry
Grok models work seamlessly with PromptLayer’s Prompt Registry:- Select Grok models when creating or editing prompt templates
- Use templates with Grok models in evaluations
- Track and analyze xAI API usage alongside other providers
Parameter Compatibility
SDK Usage
Once you’ve set up your xAI custom provider and created a prompt template in the dashboard, you can run it programmatically with the PromptLayer SDK:Using
promptlayer.run() ensures your requests are properly logged to PromptLayer and leverages your prompt templates from the Prompt Registry. This is the recommended approach for production use, and it handles any parameter compatibility differences automatically based on your template configuration.
