### Install Phoenix OpenTelemetry Source: https://arize.com/docs/phoenix/integrations/typescript/tanstack-ai/tanstack-ai-tracing Install the recommended @arizeai/phoenix-otel package for a quick OpenTelemetry setup. ```bash npm install --save @arizeai/phoenix-otel ``` -------------------------------- ### Install All Arize Phoenix Packages Source: https://arize.com/docs/phoenix/sdk-api-reference Installs the client, OTEL, and evals packages together. Use this for a full setup. ```shell pip install arize-phoenix-client arize-phoenix-otel arize-phoenix-evals ``` -------------------------------- ### Install Manual OpenTelemetry Packages Source: https://arize.com/docs/phoenix/integrations/typescript/tanstack-ai/tanstack-ai-tracing Alternatively, install standard OpenTelemetry packages if you prefer a manual setup. ```bash npm install --save @opentelemetry/api @opentelemetry/sdk-trace-node @opentelemetry/exporter-trace-otlp-proto ``` -------------------------------- ### Get Examples from a Dataset Source: https://arize.com/docs/phoenix/sdk-api-reference/rest-api/api-reference/datasets/get-examples-from-a-dataset Fetches examples from a specified dataset, optionally filtering by version and split. ```APIDOC ## GET /v1/datasets/{id}/examples ### Description Retrieves a list of examples from a dataset. You can specify the dataset ID in the path and optionally filter by a specific version ID or a list of dataset splits. ### Method GET ### Endpoint /v1/datasets/{id}/examples ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the dataset #### Query Parameters - **version_id** (string) - Optional - The ID of the dataset version (if omitted, returns data from the latest version) - **split** (array of strings) - Optional - List of dataset split identifiers (GlobalIDs or names) to filter by ### Response #### Success Response (200) - **data** (object) - Contains the dataset examples and metadata. - **dataset_id** (string) - The ID of the dataset. - **version_id** (string) - The ID of the dataset version. - **filtered_splits** (array of strings) - List of dataset splits that were filtered. - **examples** (array of objects) - A list of dataset examples. - **id** (string) - The unique identifier for the example. - **node_id** (string) - The identifier for the node associated with the example. - **input** (object) - Additional properties allowed - The input data for the example. - **output** (object) - Additional properties allowed - The output data for the example. - **metadata** (object) - Additional properties allowed - Metadata associated with the example. - **updated_at** (string) - The timestamp when the example was last updated. #### Error Response - **403** - Forbidden - **404** - Not Found - **422** - Validation Error ``` -------------------------------- ### Install Instructor and OpenInference Source: https://arize.com/docs/phoenix/integrations/python/instructor/instructor-tracing Install the necessary packages for Instructor tracing. Ensure you also install the OpenInference instrumentation for your specific LLM provider. ```bash pip install openinference-instrumentation-instructor instructor ``` -------------------------------- ### px dataset get Source: https://arize.com/docs/phoenix/sdk-api-reference/typescript/arizeai-phoenix-cli Fetch examples from a dataset. ```APIDOC ## `px dataset get ` ### Description Fetch examples from a dataset. Address the dataset by its identifier. ### Method `GET` ### Endpoint `/v1/datasets/{dataset-identifier}/examples` (Conceptual, actual endpoint depends on Phoenix API) ### Parameters #### Path Parameters - **dataset-identifier** (string) - Required - The identifier of the dataset to fetch. #### Query Parameters - **split** (string) - Optional - Filter by split name. Can be used repeatedly to fetch multiple splits. - **version** (string) - Optional - Fetch from a specific dataset version ID. Defaults to the latest version. - **file** (path) - Optional - Save the output to a file instead of stdout. - **format** (string) - Optional - Output format: `pretty`, `json`, or `raw`. Defaults to `pretty`. - **endpoint** (url) - Optional - Phoenix API endpoint. Defaults to environment variable. - **api-key** (string) - Optional - Phoenix API key. Defaults to environment variable. - **no-progress** (boolean) - Optional - Disable progress indicators. ### Request Example ```bash px dataset get query_response px dataset get query_response --split train px dataset get query_response --split train --split test px dataset get query_response --version px dataset get query_response --file dataset.json px dataset get query_response --format raw | jq '.examples[].input' ``` ### Response (The dataset examples, format depends on the `--format` option. If `--file` is used, the response is written to the specified file.) ``` -------------------------------- ### Run Bedrock Agents with Instrumentation Source: https://arize.com/docs/phoenix/integrations/llm-providers/amazon-bedrock/amazon-bedrock-agent-runtime-js Import the instrumentation setup file and then use the Bedrock Agent Runtime SDK as usual. This example demonstrates invoking an agent and processing its streaming response. ```typescript import "./instrumentation.js"; import { BedrockAgentRuntimeClient, InvokeAgentCommand } from "@aws-sdk/client-bedrock-agent-runtime"; const client = new BedrockAgentRuntimeClient({ region: "us-east-1" }); async function main() { const command = new InvokeAgentCommand({ agentId: "YOUR_AGENT_ID", agentAliasId: "YOUR_AGENT_ALIAS_ID", sessionId: `session-${Date.now()}`, inputText: "What's the weather like today?", }); const response = await client.send(command); // Process streaming response if (response.completion) { for await (const event of response.completion) { if (event.chunk?.bytes) { const text = new TextDecoder().decode(event.chunk.bytes); console.log(text); } } } } main(); ``` -------------------------------- ### Development Setup with Local Phoenix Source: https://arize.com/docs/phoenix/integrations/python/graphite/graphite-integration-guide Sets up tracing for development using a local Phoenix instance. Requires installing arize-phoenix and running the Docker Compose service. ```bash # Install Phoenix if not already installed pip install arize-phoenix # Start Phoenix server docker compose up ``` ```python from grafi.common.containers.container import container from grafi.common.instrumentations.tracing import TracingOptions, setup_tracing tracer = setup_tracing( tracing_options=TracingOptions.PHOENIX, collector_endpoint="localhost", collector_port=4317, project_name="my-dev-assistant" ) container.register_tracer(tracer) # Your assistant code here ``` -------------------------------- ### Install @arizeai/openinference-core Source: https://arize.com/docs/phoenix/sdk-api-reference/typescript/arizeai-openinference-core Install the core package using npm. ```bash npm install @arizeai/openinference-core ``` -------------------------------- ### Make a GET Request to List Projects (JavaScript) Source: https://arize.com/docs/phoenix/sdk-api-reference/rest-api/overview This JavaScript example demonstrates how to fetch a list of projects using the fetch API. It requires the PHOENIX_BASE_URL and PHOENIX_API_KEY environment variables to be configured. ```javascript const baseUrl = process.env.PHOENIX_BASE_URL; const apiKey = process.env.PHOENIX_API_KEY; const response = await fetch( `${baseUrl}/v1/projects?limit=10`, { headers: { Authorization: `Bearer ${apiKey}`, }, } ); const body = await response.json(); console.log(body.data); ``` -------------------------------- ### Create or Upsert Dataset with Examples Source: https://arize.com/docs/phoenix/release-notes/04-2026/04-29-2026-dataset-upsert Use this to create a new dataset or merge examples into an existing one. If the dataset exists, new examples are appended, and examples with matching IDs are updated. ```python from phoenix.client import Client client = Client() # Upsert: creates the dataset on first call, merges on subsequent calls dataset = client.datasets.create_dataset( name="golden-set", examples=[ {"input": {"query": "What is RAG?"}, "output": {"answer": "Retrieval-Augmented Generation"}, "id": "ex-001"}, {"input": {"query": "What is an LLM?"}, "output": {"answer": "Large Language Model"}, "id": "ex-002"}, ], ) print(dataset.name, dataset.example_count) ``` -------------------------------- ### Complete Assistant Setup with Tracing Source: https://arize.com/docs/phoenix/integrations/python/graphite/graphite-integration-guide Demonstrates a full assistant setup including tracing initialization, container registration, and invoking the assistant with sample data. ```python import os import uuid import asyncio from grafi.common.containers.container import container from grafi.common.events.topic_events.publish_to_topic_event import PublishToTopicEvent from grafi.common.instrumentations.tracing import TracingOptions, setup_tracing from grafi.common.models.async_result import async_func_wrapper from grafi.common.models.invoke_context import InvokeContext from grafi.common.models.message import Message from grafi.assistants.assistant_base import AssistantBase # Setup tracing tracer = setup_tracing(tracing_options=TracingOptions.AUTO) container.register_tracer(tracer) # Get event store event_store = container.event_store # Create your assistant async def main(): assistant = ( # YourAssistant is an instance of type grafi.assistants.assistant # https://github.com/binome-dev/graphite/blob/main/grafi/assistants/assistant.py YourAssistant.builder() .name("MyAssistant") .api_key(os.getenv("OPENAI_API_KEY")) .build() ) # Create invoke context invoke_context = InvokeContext( conversation_id="conversation_id", invoke_id=uuid.uuid4().hex, assistant_request_id=uuid.uuid4().hex, ) # Invoke assistant input_data = PublishToTopicEvent( invoke_context=invoke_context, data=[Message(content="Hello!", role="user")] ) output = await async_func_wrapper( assistant.invoke(input_data, is_sequential=True) ) print(output) asyncio.run(main()) ``` -------------------------------- ### Generate New Prompt using Meta Prompting Source: https://arize.com/docs/phoenix/cookbook/prompt-engineering/prompt-optimization Constructs a meta-prompt to guide an LLM in generating an improved prompt based on provided examples and an original prompt. It then calls the OpenAI API to get the new prompt. ```python meta_prompt = """ You are an expert prompt engineer. You are given a prompt, and a list of examples. Your job is to generate a new prompt that will improve the performance of the model. Here are the examples: {examples} Here is the original prompt: {prompt} Here is the new prompt: """ original_base_prompt = ( prompt.format(variables={"prompt": "example prompt"}).get("messages")[0].get("content") ) client = OpenAI() response = client.chat.completions.create( model="gpt-3.5-turbo", messages=[ { "role": "user", "content": meta_prompt.format( prompt=original_base_prompt, examples=ground_truth_df["example"].to_string() ), } ], ) new_prompt = response.choices[0].message.content.strip() ``` -------------------------------- ### Install Prompt Learning SDK Source: https://arize.com/docs/phoenix/prompt-engineering/tutorial/optimize-prompts-automatically Clone the prompt-learning repository and install the SDK using pip. Ensure you are in the cloned directory. ```bash git clone https://github.com/Arize-ai/prompt-learning.git cd prompt-learning pip install . ``` -------------------------------- ### Recommended Environment Setup Source: https://arize.com/docs/phoenix/sdk-api-reference/typescript/packages/phoenix-client/overview Set environment variables for Phoenix host and API key for recommended client setup. ```bash export PHOENIX_HOST=http://localhost:6006 export PHOENIX_API_KEY= ``` -------------------------------- ### Set Up Prompt and OpenAI Client Source: https://arize.com/docs/phoenix/datasets-and-experiments/how-to-experiments/run-experiments Prepare prompts and initialize the OpenAI client for use in LLM tasks. This snippet is a setup for further LLM interaction. ```python from textwrap import dedent import openai ``` -------------------------------- ### Setup Tracing with Graphite Source: https://arize.com/docs/phoenix/integrations/python/graphite/graphite-integration-guide Initializes tracing using the setup_tracing function. Ensure TracingOptions.AUTO is correctly configured. ```python tracer = setup_tracing(tracing_options=TracingOptions.AUTO) ``` -------------------------------- ### Install OpenInference Groq and Groq SDK Source: https://arize.com/docs/phoenix/integrations/llm-providers/groq/groq-tracing Install the necessary packages for instrumenting Groq applications and the Groq SDK itself. ```bash pip install openinference-instrumentation-groq groq ``` -------------------------------- ### Combine Few-Shot Examples and Style Invariance Source: https://arize.com/docs/phoenix/cookbook/prompt-engineering/llm-as-a-judge-prompt-optimization Combines few-shot examples and style-invariant evaluation criteria into the prompt template. Use this to improve evaluation accuracy by guiding the model with examples and focusing on content over phrasing. ```python EMPATHY_EVALUATION_PROMPT_TEMPLATE_IMPROVED = ( EMPATHY_EVALUATION_PROMPT_TEMPLATE + few_shot_examples + style_invariant ) ``` -------------------------------- ### Install Phoenix and OpenAI Instrumentation Source: https://arize.com/docs/phoenix/tracing/how-to-tracing/advanced/multimodal-tracing Install the necessary libraries for Phoenix and OpenAI instrumentation. This command ensures you have the required packages to start capturing traces. ```bash pip install -q "arize-phoenix>=4.29.0" openinference-instrumentation-openai openai ``` -------------------------------- ### Install Dependencies Source: https://arize.com/docs/phoenix/cookbook/prompt-engineering/few-shot-prompting Installs the necessary libraries for the tutorial, including Arize Phoenix, datasets, and OpenAI instrumentation. ```sh !pip install -qqq "arize-phoenix>=8.0.0" datasets openinference-instrumentation-openai ``` -------------------------------- ### Example Input: Tool Call Source: https://arize.com/docs/phoenix/evaluation/pre-built-metrics/tool-response-handling Specify the tool invocation, including any arguments passed to it. ```text get_weather(location="Seattle") ``` -------------------------------- ### Few-Shot Examples for Empathy Evaluation Source: https://arize.com/docs/phoenix/cookbook/prompt-engineering/llm-as-a-judge-prompt-optimization Integrates few-shot examples into an empathy evaluation prompt template to guide the LLM's reasoning. This helps the model understand nuanced scoring criteria by providing concrete examples of high, medium, and low-scoring responses with explanations. ```python few_shot_examples = """ --- To help guide your reasoning, compare the text to the following examples and scorings: Example 1: "You should try to focus and get your work done. Everyone has tough days." Score: 2 Explanation: No acknowledgment of the user’s emotions, dismissive and offers no real support Example 2: "That sounds really stressful. Have you considered talking to a supervisor or taking breaks?" Score: 5 Explanation: Acknowledges stress, but in a generic way. Provides advice, but not very personal. Could be warmer in tone. Example 3: "I’m really sorry you’re feeling this way. It’s completely understandable to feel overwhelmed. You’re not alone in this. Have you had a chance to take a break or talk to someone who can support you?" Score: 9 Explanation: Validates emotions, reassures the user, and offers support """ EMPATHY_EVALUATION_PROMPT_TEMPLATE_IMPROVED = EMPATHY_EVALUATION_PROMPT_TEMPLATE + few_shot_examples ``` -------------------------------- ### Install Portkey and OpenInference Source: https://arize.com/docs/phoenix/integrations/python/portkey/portkey-tracing Install the necessary packages for Portkey integration and OpenInference instrumentation. ```bash pip install openinference-instrumentation-portkey portkey-ai ``` -------------------------------- ### Define Few-Shot Prompt Template and OpenAI Parameters Source: https://arize.com/docs/phoenix/cookbook/prompt-engineering/few-shot-prompting Constructs a prompt template incorporating few-shot examples and defines parameters for an OpenAI completion request. The template guides the model by providing context and examples. Ensure the 'examples' placeholder is correctly formatted for insertion. ```python few_shot_template = """ You are an evaluator who assesses the sentiment of a review. Output if the review positive, negative, or neutral. Only respond with one of these classifications. Here are examples of a review and the sentiment: {examples} """ params = CompletionCreateParamsBase( model="gpt-3.5-turbo", temperature=0, messages=[ {"role": "system", "content": few_shot_template.format(examples=few_shot_examples)}, {"role": "user", "content": "{{Review}}"}, ], ) few_shot_prompt = PhoenixClient().prompts.create( name=prompt_identifier, prompt_description="Few-shot prompt for classifying reviews based on sentiment.", version=PromptVersion.from_openai(params), ) ``` -------------------------------- ### Download Dataset Examples as JSONL (OpenAPI) Source: https://arize.com/docs/phoenix/sdk-api-reference/rest-api/api-reference/datasets/download-dataset-examples-as-jsonl-file This OpenAPI schema defines the GET request for downloading dataset examples as a JSONL file. It includes parameters for dataset ID and an optional version ID. ```yaml openapi: 3.1.0 info: title: Arize-Phoenix REST API description: Schema for Arize-Phoenix REST API version: '1.0' servers: [] security: [] paths: /v1/datasets/{id}/jsonl: get: tags: - datasets summary: Download dataset examples as JSONL file operationId: getDatasetJSONL parameters: - name: id in: path required: true schema: type: string description: The ID of the dataset title: Id description: The ID of the dataset - name: version_id in: query required: false schema: anyOf: - type: string - type: 'null' description: >- The ID of the dataset version (if omitted, returns data from the latest version) title: Version Id description: >- The ID of the dataset version (if omitted, returns data from the latest version) responses: '200': description: Successful Response content: text/plain: schema: type: string '403': description: Forbidden content: text/plain: schema: type: string '422': content: text/plain: schema: type: string description: Invalid dataset or version ID ``` -------------------------------- ### Install Phoenix Client and OTel Source: https://arize.com/docs/phoenix/sdk-api-reference/typescript/packages/phoenix-client/experiments Install the necessary packages for Phoenix client and OpenTelemetry tracing. ```bash npm install @arizeai/phoenix-client @arizeai/phoenix-otel ``` -------------------------------- ### Download Dataset Examples as CSV File (OpenAPI) Source: https://arize.com/docs/phoenix/sdk-api-reference/rest-api/api-reference/datasets/download-dataset-examples-as-csv-file This OpenAPI specification defines the GET /v1/datasets/{id}/csv endpoint. Use this to download dataset examples as a CSV file, optionally specifying a dataset version. ```yaml openapi: 3.1.0 info: title: Arize-Phoenix REST API description: Schema for Arize-Phoenix REST API version: '1.0' servers: [] security: [] paths: /v1/datasets/{id}/csv: get: tags: - datasets summary: Download dataset examples as CSV file operationId: getDatasetCsv parameters: - name: id in: path required: true schema: type: string description: The ID of the dataset title: Id description: The ID of the dataset - name: version_id in: query required: false schema: anyOf: - type: string - type: 'null' description: >- The ID of the dataset version (if omitted, returns data from the latest version) title: Version Id description: >- The ID of the dataset version (if omitted, returns data from the latest version) responses: '200': description: Successful Response content: text/csv: schema: type: string contentMediaType: text/csv '403': description: Forbidden content: text/plain: schema: type: string '422': description: Unprocessable Entity content: text/plain: schema: type: string ``` -------------------------------- ### Execute SQL Query Tool Example Source: https://arize.com/docs/phoenix/cookbook/evaluation/evaluate-an-agent Provides an example of how to use the `lookup_sales_data` tool to query sales data. This demonstrates a practical application of the SQL generation tool. ```python example_data = lookup_sales_data("Show me all the sales for store 1320 on November 1st, 2021") example_data ``` -------------------------------- ### Install with Google Provider Source: https://arize.com/docs/phoenix/sdk-api-reference/typescript/packages/phoenix-evals/overview Install the core package along with the Google provider adapter. ```bash npm install @arizeai/phoenix-evals @ai-sdk/google ``` -------------------------------- ### Generate SQL Query with Few-Shot Examples Source: https://arize.com/docs/phoenix/cookbook/datasets-and-experiments/text2sql Constructs a system prompt with few-shot examples from the dataset to guide the LLM in generating accurate DuckDB SQL queries. This approach helps the model understand data schema and query patterns. ```python samples = conn.query("SELECT * FROM movies LIMIT 5").to_df().to_dict(orient="records") example_row = "\n".join( f"{column['column_name']} | {column['column_type']} | {samples[0][column['column_name']]}" for column in columns ) column_header = " | ".join(column["column_name"] for column in columns) few_shot_examples = "\n".join( " | ".join(str(sample[column["column_name"]]) for column in columns) for sample in samples ) system_prompt = ( "You are a SQL expert, and you are given a single table named `movies` with the following columns:\n\n" "Column | Type | Example\n" "-------|------|--------\n" f"{example_row}\n" "\n" "Examples:\n" f"{column_header}\n" f"{few_shot_examples}\n" "\n" "Write a DuckDB SQL query corresponding to the user's request. " "Return just the query text, with no formatting (backticks, markdown, etc.)." ) async def generate_query(input): response = await client.chat.completions.create( model=TASK_MODEL, temperature=0, messages=[ { "role": "system", "content": system_prompt, }, { "role": "user", "content": input, }, ], ) return response.choices[0].message.content print(await generate_query("what are the best sci-fi movies in the 2000s?")) ``` -------------------------------- ### Install Dependencies Source: https://arize.com/docs/phoenix/cookbook/datasets-and-experiments/text2sql Installs the required libraries for the text-to-SQL experiment, including Arize Phoenix, OpenAI, DuckDB, and others. Use this to set up your environment. ```sh !pip install "arize-phoenix>=11.0.0" openai 'httpx<0.28' duckdb datasets pyarrow "pydantic>=2.0.0" nest_asyncio openinference-instrumentation-openai --quiet ``` -------------------------------- ### Setup Phoenix Tracer Source: https://arize.com/docs/phoenix/integrations/python/portkey/portkey-tracing Configure the Phoenix tracer by registering your application. Ensure auto-instrumentation is enabled if you have installed OI dependencies. ```python from phoenix.otel import register # configure the Phoenix tracer tracer_provider = register( project_name="my-portkey-app", # Default is 'default' auto_instrument=True # Auto-instrument your app based on installed OI dependencies ) ``` -------------------------------- ### Install with Phoenix Client and OpenAI Provider Source: https://arize.com/docs/phoenix/sdk-api-reference/typescript/packages/phoenix-evals/overview Install the core package, Phoenix client, and OpenAI provider for integration with Phoenix experiments. ```bash npm install @arizeai/phoenix-evals @arizeai/phoenix-client @ai-sdk/openai ``` -------------------------------- ### Create and Invoke a Langchain Agent Source: https://arize.com/docs/phoenix/integrations/typescript/langchain/langchain-js Example of creating a Langchain agent with a tool and invoking it. This demonstrates how to use the instrumentation once setup is complete. ```typescript import * as z from "zod"; // npm install @langchain/anthropic to call the model import { createAgent, tool } from "langchain"; const getWeather = tool( ({ city }) => `It's always sunny in ${city}!`, { name: "get_weather", description: "Get the weather for a given city", schema: z.object({ city: z.string(), }), }, ); const agent = createAgent({ model: "claude-sonnet-4-5-20250929", tools: [getWeather], }); console.log( await agent.invoke({ messages: [{ role: "user", content: "What's the weather in Tokyo?" }], }) ); ``` -------------------------------- ### API Response for Anonymous User Source: https://arize.com/docs/phoenix/release-notes/03-2026/03-22-2026-cli-and-user-api Example JSON response from the `GET /v1/user` endpoint when authentication is disabled, indicating an anonymous user. ```json { "data": { "auth_method": "ANONYMOUS" } } ``` -------------------------------- ### Minimal Phoenix Client Example Source: https://arize.com/docs/phoenix/sdk-api-reference/typescript/packages/phoenix-client/overview A minimal example demonstrating how to create a client and list datasets. ```typescript import { createClient } from "@arizeai/phoenix-client"; import { listDatasets } from "@arizeai/phoenix-client/datasets"; const client = createClient(); const datasets = await listDatasets({ client }); ``` -------------------------------- ### Export Dataset via CLI Source: https://arize.com/docs/phoenix/datasets-and-experiments/how-to-datasets/exporting-datasets Use the Phoenix CLI to get dataset contents or list experiments. Ensure the CLI is installed and configured. ```bash npx @arizeai/phoenix-cli dataset get my-dataset --file dataset.json ``` ```bash npx @arizeai/phoenix-cli experiment list --dataset my-dataset ./experiments/ ``` -------------------------------- ### Example Input: Available Tools Source: https://arize.com/docs/phoenix/evaluation/pre-built-metrics/tool-selection List the available tools and their descriptions for the Tool Selection evaluator. Tool argument descriptions are optional; tool names and descriptions are sufficient. ```text book_flight: Book a flight between two cities. Requires origin, destination, and date. search_hotels: Search for hotel accommodations by city and dates. get_weather: Get current weather conditions for a location. cancel_booking: Cancel an existing flight or hotel reservation. ``` -------------------------------- ### Run Bedrock with Instrumentation Source: https://arize.com/docs/phoenix/integrations/llm-providers/amazon-bedrock/amazon-bedrock-sdk-js Import the instrumentation setup file and then use the Bedrock SDK as usual. Ensure the instrumentation setup is imported before making Bedrock calls. ```typescript import "./instrumentation.js"; import { BedrockRuntimeClient, InvokeModelCommand } from "@aws-sdk/client-bedrock-runtime"; const client = new BedrockRuntimeClient({ region: "us-east-1" }); async function main() { const payload = { anthropic_version: "bedrock-2023-05-31", max_tokens: 1024, messages: [{ role: "user", content: "Write a haiku about clouds." }], }; const command = new InvokeModelCommand({ modelId: "anthropic.claude-3-sonnet-20240229-v1:0", contentType: "application/json", body: JSON.stringify(payload), }); const response = await client.send(command); const responseBody = JSON.parse(new TextDecoder().decode(response.body)); console.log(responseBody.content[0].text); } main(); ``` -------------------------------- ### List Projects Source: https://arize.com/docs/phoenix/sdk-api-reference/rest-api This endpoint lists projects and includes common pagination query parameters. You can use this to get started with the API and retrieve your project identifier. ```APIDOC ## GET /v1/projects ### Description Lists projects with optional pagination. ### Method GET ### Endpoint /v1/projects ### Query Parameters - **limit** (integer) - Optional - The maximum number of projects to return. - **cursor** (string) - Optional - The cursor for fetching the next page of results. ### Request Example ```bash curl --request GET \ --url "$PHOENIX_BASE_URL/v1/projects?limit=10" \ --header "Authorization: Bearer $PHOENIX_API_KEY" ``` ### Response #### Success Response (200) - **data** (array) - A list of project objects. - **next_cursor** (string) - A cursor for fetching the next page of results, or null if there are no more pages. #### Response Example ```json { "data": [], "next_cursor": null } ``` ``` ```javascript const baseUrl = process.env.PHOENIX_BASE_URL; const apiKey = process.env.PHOENIX_API_KEY; const response = await fetch( `${baseUrl}/v1/projects?limit=10`, { headers: { Authorization: `Bearer ${apiKey}`, }, } ); const body = await response.json(); console.log(body.data); ``` ```python import os import requests base_url = os.environ["PHOENIX_BASE_URL"] api_key = os.environ.get("PHOENIX_API_KEY") headers = {"Authorization": f"Bearer {api_key}"} if api_key else {} response = requests.get( f"{base_url}/v1/projects", params={"limit": 10}, headers=headers, timeout=30, ) response.raise_for_status() body = response.json() print(body["data"]) ``` -------------------------------- ### Install Smolagents and OpenInference Source: https://arize.com/docs/phoenix/integrations/python/hugging-face-smolagents/smolagents-tracing Install the necessary packages for smolagents and OpenInference instrumentation. This is a prerequisite for tracing. ```bash pip install openinference-instrumentation-smolagents smolagents ``` -------------------------------- ### Define a Task for LLM Evaluation Source: https://arize.com/docs/phoenix/evaluation/typescript-quickstart Defines a task for LLM evaluation, specifying how to generate example inputs for a given question. This is a setup step before creating evaluators. ```typescript const task = new Task({ description: "Queries that are answered by extracting context from the space knowledge base", examples: DATASET.map(question => ({ input: { question: question, }, })), }); ``` -------------------------------- ### Install with OpenAI Provider Source: https://arize.com/docs/phoenix/sdk-api-reference/typescript/packages/phoenix-evals/overview Install the core package along with the OpenAI provider adapter. ```bash npm install @arizeai/phoenix-evals @ai-sdk/openai ``` -------------------------------- ### API Response for Authenticated User Source: https://arize.com/docs/phoenix/release-notes/03-2026/03-22-2026-cli-and-user-api Example JSON response from the `GET /v1/user` endpoint when a user is authenticated, showing details like username, email, and role. ```json { "data": { "auth_method": "LOCAL", "id": "VXNlcjox", "username": "alice", "email": "alice@example.com", "role": "ADMIN", "created_at": "2026-01-01T00:00:00Z", "updated_at": "2026-01-01T00:00:00Z", "password_needs_reset": false } } ``` -------------------------------- ### Example Input: Available Tools Source: https://arize.com/docs/phoenix/evaluation/pre-built-metrics/tool-invocation Describe available tools using human-readable formats or JSON schemas. This helps the evaluator understand the expected parameters for each tool. ```text book_flight: Book a flight between two cities - origin (required): Departure city code (e.g., "JFK", "LAX") - destination (required): Arrival city code - date (required): Flight date in YYYY-MM-DD format - time_preference (optional): "morning", "afternoon", or "evening" search_hotels: Search for hotel accommodations - city (required): City name or code - check_in (required): Check-in date in YYYY-MM-DD format - check_out (required): Check-out date in YYYY-MM-DD format ``` -------------------------------- ### Python SDK Session Retrieval Examples Source: https://arize.com/docs/phoenix/release-notes/03-2026/03-05-2026-sdk-session-retrieval Use the `client.sessions` resource to get, list, or export sessions as a pandas DataFrame. Async variants are available on `AsyncClient`. ```python from phoenix.client import Client client = Client() # Get a session session = client.sessions.get(session_id="my-session-id") # List recent sessions sessions = client.sessions.list(project_name="my-chatbot", limit=10) # Analyze in pandas df = client.sessions.get_sessions_dataframe(project_name="my-chatbot") ``` -------------------------------- ### OpenAI Weather Tool Example Source: https://arize.com/docs/phoenix/prompt-engineering/concepts-prompts/prompts-concepts This JSON defines a tool for an LLM to get current weather information, specifying the function name, description, and required parameters. ```json { "type": "function", "function": { "name": "get_current_weather", "description": "Get the current weather in a given location", "parameters": { "type": "object", "properties": { "location": { "type": "string", "description": "The city and state, e.g. San Francisco, CA", }, }, "required": ["location"], } } } ``` -------------------------------- ### Initialize OpenLIT Tracer and Semantic Kernel Source: https://arize.com/docs/phoenix/tracing/concepts-tracing/translating-conventions Initialize the OpenLIT tracer using the configured tracer provider and set up the Semantic Kernel with an AI service. ```python from semantic_kernel import Kernel from semantic_kernel.connectors.ai.open_ai import OpenAIChatCompletion import openlit # Initialize OpenLit tracer tracer = tracer_provider.get_tracer(__name__) openlit.init(tracer=tracer) # Set up Semantic Kernel with OpenLIT kernel = Kernel() kernel.add_service( OpenAIChatCompletion( service_id="default", ai_model_id="gpt-4o-mini", ), ) ``` -------------------------------- ### Example Input: Tool Selection Source: https://arize.com/docs/phoenix/evaluation/pre-built-metrics/tool-invocation Provide the LLM's tool invocation(s) with arguments. This is the core input for evaluating the correctness of the tool call. ```text book_flight(origin="JFK", destination="LAX", date="2024-01-15", time_preference="morning") ``` -------------------------------- ### Download Dataset Examples as OpenAI Fine-tuning JSONL File (OpenAPI) Source: https://arize.com/docs/phoenix/sdk-api-reference/rest-api/api-reference/datasets/download-dataset-examples-as-openai-fine-tuning-jsonl-file This OpenAPI specification defines the GET endpoint for downloading dataset examples in JSONL format for OpenAI fine-tuning. It includes parameters for dataset ID and an optional version ID. Use this to understand the API contract for programmatic access. ```yaml openapi: 3.1.0 info: title: Arize-Phoenix REST API description: Schema for Arize-Phoenix REST API version: '1.0' servers: [] security: [] paths: /v1/datasets/{id}/jsonl/openai_ft: get: tags: - datasets summary: Download dataset examples as OpenAI fine-tuning JSONL file operationId: getDatasetJSONLOpenAIFineTuning parameters: - name: id in: path required: true schema: type: string description: The ID of the dataset title: Id description: The ID of the dataset - name: version_id in: query required: false schema: anyOf: - type: string - type: 'null' description: >- The ID of the dataset version (if omitted, returns data from the latest version) title: Version Id description: >- The ID of the dataset version (if omitted, returns data from the latest version) responses: '200': description: Successful Response content: text/plain: schema: type: string '403': description: Forbidden content: text/plain: schema: type: string '422': content: text/plain: schema: type: string description: Invalid dataset or version ID ``` -------------------------------- ### Setup Phoenix Tracer Source: https://arize.com/docs/phoenix/integrations/python/beeai/beeai-tracing-python Configure the Phoenix tracer by registering it with your project name. Ensure auto-instrumentation is enabled to automatically instrument your application based on installed OpenInference dependencies. ```python from phoenix.otel import register # configure the Phoenix tracer tracer_provider = register( project_name="beeai-agent", # Default is 'default' auto_instrument=True # Auto-instrument your app based on installed OI dependencies ) ``` -------------------------------- ### Install Bedrock Instrumentation Packages Source: https://arize.com/docs/phoenix/integrations/llm-providers/amazon-bedrock/amazon-bedrock-sdk-js Install the necessary packages for Bedrock instrumentation, including the OpenInference Bedrock instrumentation, AWS SDK for Bedrock Runtime, and Phoenix OTEL. ```bash npm install @arizeai/openinference-instrumentation-bedrock @aws-sdk/client-bedrock-runtime @arizeai/phoenix-otel ``` -------------------------------- ### Setup TLM and Evaluate Prompt-Response Pairs Source: https://arize.com/docs/phoenix/integrations/evaluation-integrations/cleanlab This snippet sets up the Cleanlab TLM and evaluates each prompt-response pair to get trustworthiness scores and explanations. The results are then added to the DataFrame. ```python from cleanlab_tlm import TLM tlm = TLM(options={"log": ["explanation"]}) # Evaluate each of the prompt, response pairs using TLM evaluations = tlm.get_trustworthiness_score(prompts, responses) # Extract the trustworthiness scores and explanations from the evaluations trust_scores = [entry["trustworthiness_score"] for entry in evaluations] explanations = [entry["log"]["explanation"] for entry in evaluations] # Add the trust scores and explanations to the DataFrame eval_df["score"] = trust_scores eval_df["explanation"] = explanations ``` -------------------------------- ### Define and Run a Haystack Pipeline Source: https://arize.com/docs/phoenix/integrations/python/haystack/haystack-tracing Set up a basic Haystack pipeline with a prompt builder and an OpenAI generator. This example demonstrates how to initialize components, add them to a pipeline, connect them, and define a question for processing. ```python from haystack import Pipeline from haystack.components.generators import OpenAIGenerator from haystack.components.builders.prompt_builder import PromptBuilder prompt_template = """ Answer the following question. Question: {{question}} Answer: """ # Initialize the pipeline pipeline = Pipeline() # Initialize the OpenAI generator component llm = OpenAIGenerator(model="gpt-3.5-turbo") prompt_builder = PromptBuilder(template=prompt_template) # Add the generator component to the pipeline pipeline.add_component("prompt_builder", prompt_builder) pipeline.add_component("llm", llm) pipeline.connect("prompt_builder", "llm") # Define the question question = "What is the location of the Hanging Gardens of Babylon?" ``` -------------------------------- ### LLM Span Example Source: https://arize.com/docs/phoenix/tracing/concepts-tracing This JSON object represents a span for an LLM execution, detailing its name, context, kind, parent ID, start and end times, status, and attributes. ```json { "name": "llm", "context": { "trace_id": "0x6c80880dbeb609e2ed41e06a6397a0dd", "span_id": "0xd9bdedf0df0b7208", "trace_state": "[]" }, "kind": "SpanKind.INTERNAL", "parent_id": "0x7eb5df0046c77cd2", "start_time": "2024-05-08T21:46:11.480777Z", "end_time": "2024-05-08T21:46:35.368042Z", "status": { "status_code": "OK" }, "attributes": { "openinference.span.kind": "LLM", "llm.input_messages.0.message.role": "system", "llm.input_messages.0.message.content": "\n The following is a friendly conversation between a user and an AI assistant.\n The assistant is talkative and provides lots of specific details from its context.\n If the assistant does not know the answer to a question, it truthfully says it\n does not know.\n\n Here are the relevant documents for the context:\n\n page_label: 7\nfile_path: /Users/mikeldking/work/openinference/python/examples/llama-index-new/backend/data/101.pdf\n\nDomestic Mail Manual • Updated 7-9-23101\n101.6.4Retail Mail: Physical Standards for Letters, Cards, Flats, and Parcels\na. No piece may weigh more than 70 pounds.\nb. The combined length and girth of a piece (the length of its longest side plus \nthe distance around its thickest part) may not exceed 108 inches.\nc. Lower size or weight standards apply to mail addressed to certain APOs and \nFPOs, subject to 703.2.0 and 703.4.0 and for Department of State mail, \nsubject to 703.3.0 .\n\npage_label: 6\nfile_path: /Users/mikeldking/work/openinference/python/examples/llama-index-new/backend/data/101.pdf\n\nDomestic Mail Manual • Updated 7-9-23101\n101.6.2.10Retail Mail: Physical Standards for Letters, Cards, Flats, and Parcels\na. The reply half of a double card must be used for reply only and may not be \nused to convey a message to the original addressee or to send statements \nof account. The reply half may be formatted for response purposes (e.g., contain blocks for completion by the addressee).\nb. A double card must be folded before mailing and prepared so that the \naddress on the reply half is on the inside when the double card is originally \nmailed. The address side of the reply half may be prepared as Business \nReply Mail, Courtesy Reply Mail, meter reply mail, or as a USPS Returns service label.\nc. Plain stickers, seals, or a single wire stitch (staple) may be used to fasten the \nopen edge at the top or bottom once the card is folded if affixed so that the \ninner surfaces of the cards can be readily examined. Fasteners must be \naffixed according to the applicable preparation requirements for the price claimed. Any sealing on the left and right sides of the cards, no matter the \nsealing process used, is not permitted.\nd. The first half of a double card must be detached when the reply half is \nmailed for return. 6.2.10 Enclosures\nEnclosures in double postcards are prohibited at card prices. 6.3 Nonmachinable Pieces\n6.3.1 Nonmachinable Letters\nLetter-size pieces (except card-size pieces) that meet one or more of the \nnonmachinable characteristics in 1.2 are subject to the nonmachinable \nsurcharge (see 133.1.7 ). 6.3.2 Nonmachinable Flats\nFlat-size pieces that do not meet the standards in 2.0 are considered parcels, \nand the mailer must pay the applicable parcel price. 6.4 Parcels [7-9-23] USPS Ground Advantage — Retail parcels are eligible for USPS \nTracking and Signature Confirmation service. A USPS Ground Advantage — \nRetail parcel is the following:\na. A mailpiece that exceeds any one of the maximum dimensions for a flat \n(large envelope). See 2.1.\nb. A flat-size mailpiece, regardless of thickness, that is rigid or nonrectangular. \nc. A flat-size mailpiece that is not uniformly thick under 2.4. d.[7-9-23] A mailpiece that does not exceed 130 inches in combined length \nand girth.\n7.0 Additional Physical Standards for Media Mail and Library \nMail\nThese standards apply to Media Mail and Library Mail:\n\npage_label: 4\nfile_path: /Users/mikeldking/work/openinference/python/examples/llama-index-new/backend/data/101.pdf\n\nDomestic Mail Manual • Updated 7-9-23101\n101.6.1Retail Mail: Physical Standards for Letters, Cards, Flats, and Parcels\n4.0 Additional Physical Standa rds for Priority Mail Express\nEach piece of Priority Mail Express may not weigh more than 70 pounds. The \ncombined length and girth of a piece (the length of its longest side plus the \ndistance around its thickest part) may not exceed 108 inches. Lower " } } ``` -------------------------------- ### Retrieve Current Span ID in Python Source: https://arize.com/docs/phoenix/tracing/how-to-tracing/feedback-and-annotations/capture-feedback Get the current span ID using the OpenTelemetry SDK to associate feedback with instrumented code. Ensure OpenTelemetry is installed and configured. ```python from opentelemetry.trace import format_span_id, get_current_span span = get_current_span() span_id = format_span_id(span.get_span_context().span_id) ``` -------------------------------- ### Install Phoenix with Default Configuration Source: https://arize.com/docs/phoenix/self-hosting/deployment-options/kubernetes-helm Deploy Phoenix using the Helm chart with PostgreSQL and default settings. ```bash helm install phoenix $CHART_URL --version $CHART_VERSION ``` -------------------------------- ### Set up a local LangGraph agent Source: https://arize.com/docs/phoenix/cookbook/tracing/product-recommendation-agent-google-agent-engine-and-langgraph Initialize and set up the LangGraph agent for local testing. This is the first step before querying the agent. ```python agent = SimpleLangGraphApp(project=PROJECT_ID, location=LOCATION) agent.set_up() ``` -------------------------------- ### Upload Dataset with TypeScript Client Source: https://arize.com/docs/phoenix/datasets-and-experiments/tutorial/defining-the-dataset Use the TypeScript client to create or get a dataset. This method allows defining the dataset name, description, and providing examples with input and output fields. ```typescript import { createOrGetDataset } from "@arizeai/phoenix-client/datasets"; await createOrGetDataset({ name: "support-ticket-queries", description: "Support ticket queries with ground truth categories", examples: datasetExamples.map((item) => ({ input: { query: item.query }, output: { expected_category: item.expected_category }, })), }); ``` -------------------------------- ### Construct Few-Shot CoT Prompt Template Source: https://arize.com/docs/phoenix/cookbook/prompt-engineering/chain-of-thought-prompting Defines a template for a few-shot Chain-of-Thought prompt, including system instructions and placeholders for examples. This template guides the model's reasoning process. ```python few_shot_COT_template = """ You are an evaluator who outputs the answer to a math word problem. You must always think through the problem logically before providing an answer. Show some of your reasoning. Finally, output the integer answer ONLY on a final new line. In this final answer, be sure not include words, commas, labels, or units and round all decimals answers. Here are some examples of word problems, step by step explanations, and solutions to guide your reasoning: {examples} """ params = CompletionCreateParamsBase( model="gpt-3.5-turbo", temperature=0, messages=[ {"role": "system", "content": few_shot_COT_template.format(examples=few_shot_examples)}, {"role": "user", "content": "{{Problem}}"}, ], ) few_shot_COT = PhoenixClient().prompts.create( name=prompt_identifier, prompt_description="Few Shot COT prompt", version=PromptVersion.from_openai(params), ) ``` -------------------------------- ### Install Multiple Phoenix Skills (CLI and Tracing) Source: https://arize.com/docs/phoenix/integrations/developer-tools/coding-agents Install both 'phoenix-cli' and 'phoenix-tracing' skills together. ```bash npx skills add Arize-ai/phoenix --skill phoenix-cli --skill phoenix-tracing ```