Setup
- Install the Langtrace and xAI SDKs.
Python
- Setup environment variables:
Shell
Usage
Generate a simple output with your deployment’s model:
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
xAI introduces X’s Grok family of models.
# Install the SDK
pip install -U langtrace-python-sdk openai
export LANGTRACE_API_KEY=YOUR_LANGTRACE_API_KEY
export XAI_API_KEY=YOUR_OPENAI_API_KEY
import os
from langtrace_python_sdk import langtrace # Must precede any llm module imports
langtrace.init(api_key = os.environ['LANGTRACE_API_KEY'])
from openai import OpenAI
client = OpenAI(
# This is the default and can be omitted
api_key=os.environ["XAI_API_KEY"],
base_url="https://api.x.ai/v1",
)
# Generate a simple output with the llama3 MODEL
chat_completion = client.chat.completions.create(
messages=[
{
"role": "user",
"content": "What is LangChain?",
}
],
model="grok-beta",
)
print(chat_completion.choices[0].message.content)
