🌐 支持的 AI 服务提供商
OpenAI
platform.openai.com/docsAnthropic
docs.anthropic.comPerplexity
docs.perplexity.aiMistral AI
docs.mistral.aiGrok AI
docs.x.aiGemini
ai.google.devCohere
docs.cohere.comDeepSeek
api-docs.deepseek.comAI21
docs.ai21.com✨ XAI 平台全面支持上述所有 AI 服务提供商的模型。通过单一 API 密钥,您可以无缝调用以上任意服务商的 AI 模型,实现灵活高效的人工智能应用开发。
💻 SDK 示例代码
OpenAI SDK 示例
import os
from openai import OpenAI
XAI_API_KEY = os.getenv("XAI_API_KEY")
client = OpenAI(
api_key=XAI_API_KEY,
base_url="",
)
completion = client.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "system", "content": "You are AI"},
{"role": "user", "content": "What is the meaning of life, the universe, and everything?"},
],
)
print(completion.choices[0].message)
Anthropic SDK 示例
import os
from anthropic import Anthropic
XAI_API_KEY = os.getenv("XAI_API_KEY")
client = Anthropic(
api_key=XAI_API_KEY,
base_url="",
)
message = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=128,
system="You are AI.",
messages=[
{
"role": "user",
"content": "What is the meaning of life, the universe, and everything?",
},
],
)
print(message.content)