> ## 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

{/*<!-- markdownlint-enable MD044 -->*/}

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.

<img src="https://mintcdn.com/v2galileo/L1-piB8ckkwMmjO7/images/console-ui/experiment-create-button.png?fit=max&auto=format&n=L1-piB8ckkwMmjO7&q=85&s=db6e5a9f24dbe834e104656c89f65f12" alt="Create Experiment button" width="1238" height="580" data-path="images/console-ui/experiment-create-button.png" />

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

<img src="https://mintcdn.com/v2galileo/L1-piB8ckkwMmjO7/images/console-ui/experiment-create-modal.png?fit=max&auto=format&n=L1-piB8ckkwMmjO7&q=85&s=c9a281628c3dadbd0cacc55e2d98d432" alt="Create Experiment modal" width="2292" height="1260" data-path="images/console-ui/experiment-create-modal.png" />

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.

<img src="https://mintcdn.com/v2galileo/L1-piB8ckkwMmjO7/images/console-ui/experiment-create-result.png?fit=max&auto=format&n=L1-piB8ckkwMmjO7&q=85&s=f3f84229046f9a0f1ab8480a129e4289" alt="Create Experiment result" width="2656" height="1368" data-path="images/console-ui/experiment-create-result.png" />

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](/sdk-api/experiments/prompts) and a [dataset](/sdk-api/experiments/datasets), you need to set up an LLM integration. An integration is also required to evaluate LLM outputs with metrics.

<Steps>
  <Step title="Navigate to the Integrations page" id="step-navigate">
    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**.

    <img src="https://mintcdn.com/v2galileo/L1-piB8ckkwMmjO7/images/console-ui/integrations-user-menu.png?fit=max&auto=format&n=L1-piB8ckkwMmjO7&q=85&s=4ba1694ec13769ae154c95f956b99a7e" alt="Integrations user menu" width="1554" height="1374" data-path="images/console-ui/integrations-user-menu.png" />
  </Step>

  <Step title="Add an integration" id="step-add-integration">
    Locate the LLM provider you are using (or specify a [custom integration](/sdk-api/third-party-integrations/model-integrations/custom-model-integrations/custom-model-integrations)), then select the **+Add Integration** button.

    <img src="https://mintcdn.com/v2galileo/L1-piB8ckkwMmjO7/images/console-ui/integrations-options.png?fit=max&auto=format&n=L1-piB8ckkwMmjO7&q=85&s=28d88856324a0bec7ff425e892ca56ad" alt="LLM provider options" width="2045" height="1156" data-path="images/console-ui/integrations-options.png" />
  </Step>

  <Step title="Add settings" id="step-add-settings">
    Specify settings for your integration (such as an API key), then select **Save changes**.

    <img src="https://mintcdn.com/v2galileo/L1-piB8ckkwMmjO7/images/console-ui/integrations-openai-modal.png?fit=max&auto=format&n=L1-piB8ckkwMmjO7&q=85&s=76441ca64e237871a3f7aa1351df60c0" alt="OpenAI integration input modal" width="1292" height="600" data-path="images/console-ui/integrations-openai-modal.png" />
  </Step>
</Steps>

### Example experiment with code

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

<Steps>
  <Step title="Install dependencies" id="step-install-dependencies">
    Install the **Galileo SDK**, and the dotenv package using the following command in your terminal:

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

      ```bash TypeScript theme={null}
      npm install galileo tsx dotenv
      ```
    </CodeGroup>
  </Step>

  <Step title="Set up your environment variables" id="step-set-up-env-vars">
    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

    <CodeGroup>
      ```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"
      ```
    </CodeGroup>
  </Step>

  <Step title="Create your application code" id="step-create-your-app-code">
    Create a file called `app.py` (Python) or `app.ts` (TypeScript) and add the following code:

    <CodeGroup>
      ```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}`);
      })();
      ```
    </CodeGroup>

    <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.
    </Note>

    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.
  </Step>

  <Step title="Run your application" id="step-run-your-application">
    Run your application using the following command in your terminal:

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

      ```bash TypeScript theme={null}
      npx tsx app.ts
      ```
    </CodeGroup>
  </Step>

  <Step title="View the results in your terminal" id="step-view-the-results">
    <CodeGroup>
      ```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/...
      ```
    </CodeGroup>
  </Step>

  <Step title="See the experiment in Galileo" id="step-see-the-experiment-in-ui">
    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.

    <img src="https://mintcdn.com/v2galileo/3GNMPBqKKlviSYg4/getting-started/experiments/experiment-traces.webp?fit=max&auto=format&n=3GNMPBqKKlviSYg4&q=85&s=df94f0e69a4687b233591c34642b5e72" alt="The experiment in Galileo with 2 traces" width="3238" height="1056" data-path="getting-started/experiments/experiment-traces.webp" />

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

    <img src="https://mintcdn.com/v2galileo/3GNMPBqKKlviSYg4/getting-started/experiments/experiment-trace.webp?fit=max&auto=format&n=3GNMPBqKKlviSYg4&q=85&s=8fb6164af51a0065c332d1a4bbeb9526" alt="The first trace in the experiment in Galileo with a 0% context adherence" width="3204" height="1710" data-path="getting-started/experiments/experiment-trace.webp" />
  </Step>
</Steps>

## 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

<CardGroup cols={2}>
  <Card title="Create a dataset" icon="box" href="/sdk-api/experiments/datasets" horizontal>
    Learn how to create and manage datasets in Galileo.
  </Card>

  <Card title="Run experiments in playgrounds" icon="hand-pointer" href="/concepts/experiments/running-experiments-in-console" horizontal>
    Learn about running experiments in the Galileo console using playgrounds and datasets.
  </Card>

  <Card title="Run experiments with code" icon="code" href="/sdk-api/experiments/running-experiments" horizontal>
    Learn how to run experiments in Galileo.
  </Card>

  <Card title="Compare experiments" icon="not-equal" href="/concepts/experiments/compare" horizontal>
    Learn how to compare experiments in Galileo.
  </Card>
</CardGroup>
