Grok ↗ is s a general purpose model that can be used for a variety of tasks, including generating and understanding text, code, and function calling.
Endpoint
URL structure
When making requests to Grok ↗, replace https://api.x.ai/v1 in the URL you are currently using with https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/grok.
Prerequisites
When making requests to Grok, ensure you have the following:
Your AI Gateway Account ID.
Your AI Gateway gateway name.
An active Grok API token.
The name of the Grok model you want to use.
Examples
cURL
Use OpenAI SDK with JavaScript
If you are using the OpenAI SDK with JavaScript, you can set your endpoint like this:
Use OpenAI SDK with Python
If you are using the OpenAI SDK with Python, you can set your endpoint like this:
Use Anthropic SDK with JavaScript
If you are using the Anthropic SDK with JavaScript, you can set your endpoint like this:
Use Anthropic SDK with Python
If you are using the Anthropic SDK with Python, you can set your endpoint like this:
Was this helpful?
What did you like?
What went wrong?
Thank you for helping improve Cloudflare's documentation!