> ## Documentation Index
> Fetch the complete documentation index at: https://docs.galileo.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Run an Experiment

> Learn how to run your first experiment using prompts and datasets

Experiments allow you to evaluate prompts, models, and your application code, using well-defined inputs, against metrics of your choice.

## Run an experiment with UI

In the Galileo console UI, "Create Experiment" buttons allow you to easily add experiments to a project.

![Create Experiment button](https://mintcdn.com/v2galileo/L1-piB8ckkwMmjO7/images/console-ui/experiment-create-button.png?fit=max\&auto=format\&n=L1-piB8ckkwMmjO7\&q=85\&s=db6e5a9f24dbe834e104656c89f65f12)

You can use a sample dataset and sample prompt to create your first experiment.

![Create Experiment modal](https://mintcdn.com/v2galileo/L1-piB8ckkwMmjO7/images/console-ui/experiment-create-modal.png?fit=max\&auto=format\&n=L1-piB8ckkwMmjO7\&q=85\&s=c9a281628c3dadbd0cacc55e2d98d432)

If you don't already have an integration (e.g. with OpenAI), a "Configure integration" link appears for you to add a valid integration for a prompt.

![Create Experiment result](https://mintcdn.com/v2galileo/L1-piB8ckkwMmjO7/images/console-ui/experiment-create-result.png?fit=max\&auto=format\&n=L1-piB8ckkwMmjO7\&q=85\&s=f3f84229046f9a0f1ab8480a129e4289)

After successfully creating an experiment, you can view the results from the "Experiments" page of a Galileo project.

## Run an experiment with code

### Prerequisite: Configure an LLM integration

To run an experiment using a [prompt](https://docs.galileo.ai/sdk-api/experiments/prompts.md) and a [dataset](https://docs.galileo.ai/sdk-api/experiments/datasets.md), you need to set up an LLM integration. An integration is also required to evaluate LLM outputs with metrics.

**1. Navigate to the Integrations page**

In the Galileo console UI, navigate to the [LLM integrations page](https://app.galileo.ai/settings/integrations) by opening the user menu on the bottom-left corner, and then selecting **Integrations**.

![Integrations user menu](https://mintcdn.com/v2galileo/L1-piB8ckkwMmjO7/images/console-ui/integrations-user-menu.png?fit=max\&auto=format\&n=L1-piB8ckkwMmjO7\&q=85\&s=4ba1694ec13769ae154c95f956b99a7e)

**2. Add an integration**

Locate the provider you are using or specify a [custom integration](https://docs.galileo.ai/sdk-api/third-party-integrations/model-integrations/custom-model-integrations/custom-model-integrations.md). Select the **+Add Integration** button.

![LLM provider options](https://mintcdn.com/v2galileo/KBLAN_yGEhFXQswj/images/console-ui/integrations-options.png?fit=max\&auto=format\&n=KBLAN_yGEhFXQswj\&q=85\&s=2fd6b8f97aa9d09fcde4f29928e455ff)

**3. Add settings**

Specify settings for your integration (such as an API key), then select **Save changes**.

![OpenAI integration input modal](https://mintcdn.com/v2galileo/L1-piB8ckkwMmjO7/images/console-ui/integrations-openai-modal.png?fit=max\&auto=format\&n=L1-piB8ckkwMmjO7\&q=85\&s=76441ca64e237871a3f7aa1351df60c0)

### Example experiment with code

Below is a step-by-step guide. [Jump to the application code.](#step-create-your-app-code)

**1. Install dependencies**

Install the **Galileo SDK**, and the dotenv package using the following command in your terminal:

```bash Python theme={null}
pip install galileo python-dotenv
```

```bash TypeScript theme={null}
npm install galileo tsx dotenv
```

**2. Set up your environment variables**

Create an `.env` file in your project folder, and set:

* Your [Galileo API key](https://app.galileo.ai/settings/api-keys)
* Your Galileo project name

```ini .env theme={null}
GALILEO_API_KEY="your-galileo-api-key"
GALILEO_PROJECT="your-galileo-project-name"
# Provide the console url below if you are not using app.galileo.ai
# GALILEO_CONSOLE_URL="your-galileo-console-url"
```

**3. Create your application code**

Create a file called `app.py` (Python) or `app.ts` (TypeScript) and add the following code:

```python Python theme={null}
import os

from galileo import GalileoMetrics, Message, MessageRole
from galileo.config import GalileoPythonConfig
from galileo.datasets import create_dataset, get_dataset
from galileo.experiments import run_experiment
from galileo.prompts import create_prompt, get_prompt
from galileo.resources.models.prompt_run_settings import PromptRunSettings

# Load the environment variables
from dotenv import load_dotenv
load_dotenv()

# Create a prompt template, or load it if it already exists
prompt = get_prompt(name="My Prompt")
if not prompt:
    prompt = create_prompt(
        name="My Prompt",
        template=[
            Message(
                role=MessageRole.system,
                content="""
Galileo is the fastest way to ship reliable apps.
Galileo brings automation and insight to AI evaluations so you can
ship with confidence.
""",
            ),
            Message(role=MessageRole.user, content="{{input}}"),
        ],
    )

# Create a dataset, or load it if it already exists
dataset = get_dataset(name="My Dataset")
if not dataset:
    dataset = create_dataset(
        "My Dataset",
        content=[
            {"input": "What is Galileo?"},
            {"input": "What is Copernicus?"}
        ],
    )

# Run the experiment
experiment = run_experiment(
    experiment_name="My Experiment",
    prompt_template=prompt,
    dataset=dataset,
    metrics=[GalileoMetrics.context_adherence],
    project=os.environ.get("GALILEO_PROJECT"),
    prompt_settings=PromptRunSettings(model_alias="gpt-5-mini"),
)

# Show Galileo information
config = GalileoPythonConfig.get()
prompt_url = f"{config.console_url}prompts/{prompt.id}"
dataset_url = f"{config.console_url}datasets/{dataset.dataset.id}"

print()
print("🚀 GALILEO LOG INFORMATION:")
print(f"🔗 Prompt     : {prompt_url}")
print(f"🔗 Dataset    : {dataset_url}")
print(f"🔗 Experiment : {experiment['link']}")
```

```typescript TypeScript theme={null}
import {
    createDataset,
    createPrompt,
    GalileoMetrics,
    getDataset,
    getPrompt,
    runExperiment
} from "galileo";
import {
    DatasetDBType,
    MessageRole,
    PromptTemplate,
    PromptTemplateVersion
} from "galileo/types";
import dotenv from "dotenv";

// Load the environment variables
dotenv.config();

(async () => {
    // Create a prompt template, or load it if it already exists
    let prompt: PromptTemplate | PromptTemplateVersion;
    try {
        prompt = await getPrompt({ name: "My Prompt" });
    } catch (e) {
        prompt = await createPrompt({
            name: "My Prompt",
            template: [
                {
                    role: MessageRole.system,
                    content: `
Galileo is the fastest way to ship reliable apps.
Galileo brings automation and insight to AI evaluations so you can
ship with confidence.
`
                },
                {
                    role: MessageRole.user,
                    content: "{{input}}"
                },
            ]
        });
    }

    // Create a dataset, or load it if it already exists
    let dataset: DatasetDBType | undefined; 
    try {
        dataset = await getDataset({ name: "My Dataset" });
    }catch(e){
        dataset = await createDataset(
            [
                { "input": "What is Galileo?" },
                { "input": "What is Copernicus?" }
            ],
            "My Dataset",
        );
    }

    // Run the experiment
    const experiment = await runExperiment({
        name: "My Experiment",
        promptTemplate: prompt,
        dataset: dataset,
        metrics: [GalileoMetrics.contextAdherence],
        projectName: process.env.GALILEO_PROJECT,
        promptSettings: { modelAlias: "gpt-4.1-mini" }
    });

    const galileoConsoleUrl = (
        process.env.GALILEO_CONSOLE_URL ?? "https://app.galileo.ai")
        .replace(/\/+$/, ""
    );
    const datasetUrl = `${galileoConsoleUrl}/datasets/${dataset.id}`;

    console.log();
    console.log("🚀 GALILEO LOG INFORMATION:");
    console.log(`🔗 Dataset    : ${datasetUrl}`);
    console.log(`🔬 Experiment : ${experiment.link}`);
})();
```

> [!NOTE]
>
> This code defaults to using `gpt-5-mini`. If you want to use a different model, update the `model_alias` in the prompt settings passed to the call to run experiment.

This code creates a prompt containing a system prompt and user prompt, and the user prompt has a mustache template to inject rows from the dataset. It also creates a dataset.

It then uses these to run an experiment, measuring context adherence.

If the prompt or dataset already exist, they are loaded instead of being recreated.

**4. Run your application**

Run your application using the following command in your terminal:

```bash Python theme={null}
python app.py
```

```bash TypeScript theme={null}
npx tsx app.ts
```

**5. View the results in your terminal**

```output Terminal theme={null}
Experiment My Experiment has started and is currently processing.
Results will be available at https://app.galileo.ai/project/.../experiments/...

🚀 GALILEO LOG INFORMATION:
🔗 Prompt     : https://app.galileo.ai/prompts/...
🔗 Dataset    : https://app.galileo.ai/datasets/...
🔗 Experiment : https://app.galileo.ai/project/.../experiments/...
```

**6. See the experiment in Galileo**

Open the experiment in the Galileo console using the URL output to your terminal. You will see the logged experiment with 2 rows, one for each entry in the dataset.

![The experiment in Galileo with 2 traces](https://mintcdn.com/v2galileo/3GNMPBqKKlviSYg4/getting-started/experiments/experiment-traces.webp?fit=max\&auto=format\&n=3GNMPBqKKlviSYg4\&q=85\&s=df94f0e69a4687b233591c34642b5e72)

Select a trace to see more details, including an explanation of the metric score.

![The first trace in the experiment in Galileo with a 0% context adherence](https://mintcdn.com/v2galileo/3GNMPBqKKlviSYg4/getting-started/experiments/experiment-trace.webp?fit=max\&auto=format\&n=3GNMPBqKKlviSYg4\&q=85\&s=8fb6164af51a0065c332d1a4bbeb9526)

## Troubleshooting

* **I need a Galileo API key**: Head to [app.galileo.ai](https://app.galileo.ai) and sign up. Then head to the [API keys](https://app.galileo.ai/settings/api-keys) page to get a new API key.
* **What's my project name ?**: The project name was set when you created a new project. If you haven't created a new project, head to Galileo and select the **New Project** button.

## Next steps

> [card] [Create a dataset](https://docs.galileo.ai/sdk-api/experiments/datasets.md)
>
> Learn how to create and manage datasets in Galileo.

> [card] [Run experiments in playgrounds](https://docs.galileo.ai/concepts/experiments/running-experiments-in-console.md)
>
> Learn about running experiments in the Galileo console using playgrounds and datasets.

> [card] [Run experiments with code](https://docs.galileo.ai/sdk-api/experiments/running-experiments.md)
>
> Learn how to run experiments in Galileo.

> [card] [Compare experiments](https://docs.galileo.ai/concepts/experiments/compare.md)
>
> Learn how to compare experiments in Galileo.
