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.
https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/grok
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
.
curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/grok/v1/chat/completions \
--header 'content-type: application/json' \
--header 'Authorization: Bearer {grok_api_token}' \
"content": "What is Cloudflare?"
If you are using the OpenAI SDK with JavaScript, you can set your endpoint like this:
import OpenAI from "openai" ;
const openai = new OpenAI ( {
"https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/grok" ,
const completion = await openai . chat . completions . create ( {
"You are Grok, a chatbot inspired by the Hitchhiker's Guide to the Galaxy." ,
content : "What is the meaning of life, the universe, and everything?" ,
console . log ( completion . choices [ 0 ] . message ) ;
If you are using the OpenAI SDK with Python, you can set your endpoint like this:
from openai import OpenAI
XAI_API_KEY = os . getenv ( "XAI_API_KEY" )
base_url = "https://gateway.ai.cloudflare.com/v1/ {account_id} / {gateway_id} /grok" ,
completion = client . chat . completions . create (
{ "role" : "system" , "content" : "You are Grok, a chatbot inspired by the Hitchhiker's Guide to the Galaxy." },
{ "role" : "user" , "content" : "What is the meaning of life, the universe, and everything?" },
print ( completion . choices [ 0 ]. message )
If you are using the Anthropic SDK with JavaScript, you can set your endpoint like this:
import Anthropic from "@anthropic-ai/sdk" ;
const anthropic = new Anthropic ( {
"https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/grok" ,
const msg = await anthropic . messages . create ( {
"You are Grok, a chatbot inspired by the Hitchhiker's Guide to the Galaxy." ,
content : "What is the meaning of life, the universe, and everything?" ,
If you are using the Anthropic SDK with Python, you can set your endpoint like this:
from anthropic import Anthropic
XAI_API_KEY = os . getenv ( "XAI_API_KEY" )
base_url = "https://gateway.ai.cloudflare.com/v1/ {account_id} / {gateway_id} /grok" ,
message = client . messages . create (
system = "You are Grok, a chatbot inspired by the Hitchhiker's Guide to the Galaxy." ,
"content" : "What is the meaning of life, the universe, and everything?" ,