xAI (Grok)
xAI's Grok models with reasoning, vision, web search, and structured output.
Overview
xAI is an AI company founded by Elon Musk, offering the Grok model family with real-time knowledge access and strong reasoning capabilities.
Official Website: https://x.ai API Documentation: https://docs.x.ai
Key features
- Chat — Text generation with function calling and streaming
- Reasoning — Extended thinking for complex problems
- Vision — Image analysis and understanding
- Web search — Access to current information
- Structured output — JSON and schema-constrained responses
- Image generation — Text-to-image
- Embeddings & batch — Text embeddings and asynchronous batch processing
Using xAI with Yunxin
Address Grok models using the provider/model convention by prefixing with xai/ (for example, xai/grok-beta). Requests use the same Yunxin base URL (https://api.yuhuanstudio.com/v1) and your Yunxin sk- API key.
Usage example
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["YUNXIN_API_KEY"],
base_url="https://api.yuhuanstudio.com/v1"
)
response = client.chat.completions.create(
model="xai/grok-beta",
messages=[{"role": "user", "content": "What's the latest news?"}]
)
print(response.choices[0].message.content)import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.YUNXIN_API_KEY,
baseURL: "https://api.yuhuanstudio.com/v1",
});
const response = await client.chat.completions.create({
model: "xai/grok-beta",
messages: [{ role: "user", content: "What's the latest news?" }],
});
console.log(response.choices[0].message.content);curl https://api.yuhuanstudio.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $YUNXIN_API_KEY" \
-d '{
"model": "xai/grok-beta",
"messages": [{"role": "user", "content": "What'"'"'s the latest news?"}]
}'Available models
Query the live catalog with the Models API:
curl "https://api.yuhuanstudio.com/v1/models?provider=xai" \
-H "Authorization: Bearer $YUNXIN_API_KEY"Capabilities and pricing are tracked per model. Use GET /v1/models?provider=xai and each model's capabilities array as the authoritative source rather than relying on a hardcoded list.
Official resources
How is this guide?