litellm/integrations/arize/README.md
This integration enables using prompt versions from Arize Phoenix with LiteLLM's completion function.
{{variable}})Configure Arize Phoenix access in your application:
import litellm
# Configure Arize Phoenix access
# api_base should include your workspace, e.g., "https://app.phoenix.arize.com/s/your-workspace/v1"
api_key = "your-arize-phoenix-token"
api_base = "https://app.phoenix.arize.com/s/krrishdholakia/v1"
import litellm
# Use with completion
response = litellm.completion(
model="arize/gpt-4o",
prompt_id="UHJvbXB0VmVyc2lvbjox", # Your prompt version ID
prompt_variables={"question": "What is artificial intelligence?"},
api_key="your-arize-phoenix-token",
api_base="https://app.phoenix.arize.com/s/krrishdholakia/v1",
)
print(response.choices[0].message.content)
You can also combine prompt templates with additional messages:
response = litellm.completion(
model="arize/gpt-4o",
prompt_id="UHJvbXB0VmVyc2lvbjox",
prompt_variables={"question": "Explain quantum computing"},
api_key="your-arize-phoenix-token",
api_base="https://app.phoenix.arize.com/s/krrishdholakia/v1",
messages=[
{"role": "user", "content": "Please keep your response under 100 words."}
],
)
You can also use the prompt manager directly:
from litellm.integrations.arize.arize_phoenix_prompt_manager import ArizePhoenixPromptManager
# Initialize the manager
manager = ArizePhoenixPromptManager(
api_key="your-arize-phoenix-token",
api_base="https://app.phoenix.arize.com/s/krrishdholakia/v1",
prompt_id="UHJvbXB0VmVyc2lvbjox",
)
# Get rendered messages
messages, metadata = manager.get_prompt_template(
prompt_id="UHJvbXB0VmVyc2lvbjox",
prompt_variables={"question": "What is machine learning?"}
)
print("Rendered messages:", messages)
print("Metadata:", metadata)
Arize Phoenix prompts support the following structure:
{
"data": {
"description": "A chatbot prompt",
"model_provider": "OPENAI",
"model_name": "gpt-4o",
"template": {
"type": "chat",
"messages": [
{
"role": "system",
"content": [
{
"type": "text",
"text": "You are a chatbot"
}
]
},
{
"role": "user",
"content": [
{
"type": "text",
"text": "{{question}}"
}
]
}
]
},
"template_type": "CHAT",
"template_format": "MUSTACHE",
"invocation_parameters": {
"type": "openai",
"openai": {
"temperature": 1.0
}
},
"id": "UHJvbXB0VmVyc2lvbjox"
}
}
Variables in your prompt templates use Mustache/Handlebars syntax:
{{variable_name}} - Simple variable substitutionExample:
Template: "Hello {{name}}, your order {{order_id}} is ready!"
Variables: {"name": "Alice", "order_id": "12345"}
Result: "Hello Alice, your order 12345 is ready!"
Main class for managing Arize Phoenix prompts.
Methods:
get_prompt_template(prompt_id, prompt_variables) - Get and render a prompt templateget_available_prompts() - List available prompt IDsreload_prompts() - Reload prompts from Arize PhoenixLow-level client for Arize Phoenix API.
Methods:
get_prompt_version(prompt_version_id) - Fetch a prompt versiontest_connection() - Test API connectionThe integration provides detailed error messages:
Example:
try:
response = litellm.completion(
model="arize/gpt-4o",
prompt_id="invalid-id",
arize_config=arize_config,
)
except Exception as e:
print(f"Error: {e}")
/s/{workspace}/v1/prompt_versions/{PROMPT_VERSION_ID}Your api_base should be: https://app.phoenix.arize.com/s/{workspace}/v1
For example:
krrishdholakiahttps://app.phoenix.arize.com/s/krrishdholakia/v1UHJvbXB0VmVyc2lvbjoxYou can also fetch it via API:
curl -L -X GET 'https://app.phoenix.arize.com/s/krrishdholakia/v1/prompt_versions/UHJvbXB0VmVyc2lvbjox' \
-H 'Authorization: Bearer YOUR_TOKEN'
For issues or questions: