# Guide

This guide builds on the SDK quickstart and shows you how to model, manage, and experiment on your AI configuration using Hypertune.

You'll learn how to:

* Create custom object types to model your AI configuration
* Create flags that use those custom object types
* Access those flags to retrieve AI configuration in your code
* Update and target your AI configuration
* Run experiments on your AI configuration

## Prerequisites

[Set up Hypertune](/getting-started/set-up-hypertune.md)

## Create custom object types to model your AI configuration

Go to the **Schema** view in the dashboard. Click the **+** button in the top-right of the sidebar. Select **Object**, enter a name, and click **Create**.

<figure><img src="/files/kPUj93mR81bRA8aIrTiS" alt=""><figcaption></figcaption></figure>

By default, the new object type has no fields.

Click **+ Add** to add a new field. Enter a name, set its type, and click **Create**.

<figure><img src="/files/Dt7I7wIslHw6RzwUIDRR" alt=""><figcaption></figcaption></figure>

Repeat for each field you want to add. You can switch to the code view to make this easier. Then click **Save**.

<figure><img src="/files/4HNVFfhT8IFCQSoxeGfS" alt=""><figcaption></figcaption></figure>

```graphql
type EmailAssistantAIConfig {
  model: String!
  system: String!
  prompt(email: String!, tone: String!): String!
  maxOutputTokens: Int!
  temperature: Float!
  presencePenalty: Float!
  frequencyPenalty: Float!
  maxRetries: Int!
}
```

Note how the example above has `email` and `tone` arguments on the `prompt` flag. They are passed when calling the `prompt` flag in your code, and can be referenced as variables when writing the prompt in the Hypertune dashboard, enabling you to create a prompt template.

## Create flags for your AI configuration

Go to the **Flags** view in the dashboard. Click the **+** button in the top-right of the sidebar and select **Flag**.

<figure><img src="/files/qzOXLAdpaw9LIAnUiAIh" alt=""><figcaption></figcaption></figure>

Enter a name, set its type to the one you created earlier, and click **Create**.

<figure><img src="/files/ahHpPgFdgC2M55MLwAzY" alt=""><figcaption></figcaption></figure>

Enter the initial configuration, then click **Save**.

<figure><img src="/files/XaYVRhmRI99xXcnQlHIC" alt=""><figcaption></figcaption></figure>

## Access flags to retrieve AI configuration

Regenerate the client:

{% tabs %}
{% tab title="npm" %}

```bash
npx hypertune
```

{% endtab %}

{% tab title="yarn" %}

```bash
yarn hypertune
```

{% endtab %}

{% tab title="pnpm" %}

```bash
pnpm hypertune
```

{% endtab %}
{% endtabs %}

Then use the generated methods to access your flags:

{% code title="app/api/completion/route.ts" %}

```typescript
import { waitUntil } from '@vercel/functions'
import { generateText } from 'ai'
import getHypertune from '@/lib/getHypertune'

export async function POST(req: Request) {
  const hypertune = await getHypertune({ isRouteHandler: true })

  const aiConfig = hypertune.emailAssistantAIConfig()

  const { email, tone }: { email: string; tone: string } =
    await req.json()

  const { text } = await generateText({
    model: aiConfig.model({ fallback: 'openai/gpt-4.1' }),
    system: aiConfig.system({
      fallback: `You are a professional assistant that drafts clear, polite, and concise email replies for a busy executive.`,
    }),
    prompt: aiConfig.prompt({
      args: { email, tone },
      fallback: `Write a reply to the following email:\n\n${email}\n\nThe tone should be ${tone} and the response should address all points mentioned.`,
    }),
    maxOutputTokens: aiConfig.maxOutputTokens({ fallback: 400 }),
    temperature: aiConfig.temperature({ fallback: 0.5 }),
    presencePenalty: aiConfig.presencePenalty({ fallback: 0.1 }),
    frequencyPenalty: aiConfig.frequencyPenalty({
      fallback: 0.3,
    }),
    maxRetries: aiConfig.maxRetries({ fallback: 5 }),
  })

  waitUntil(hypertune.flushLogs())

  return Response.json({ text })
}
```

{% endcode %}

## Update your AI configuration

Go to the **Flags** view in the dashboard, and select the flag with your AI configuration from the left sidebar.

<figure><img src="/files/aa7TuKopGMqAWWLfnH5g" alt=""><figcaption></figcaption></figure>

Make your changes, then open the **Diff** view to review them. Click **Save**.

<figure><img src="/files/3dnxZActCL0RyrfGLUi4" alt=""><figcaption></figcaption></figure>

## Target your AI configuration

Go to the **Flags** view in the dashboard, and select the flag with your AI configuration from the left sidebar. Click the arrow (**>**) to view each subfield in the sidebar, and select the field you want to add a targeting rule to.

<figure><img src="/files/Ex7Lwux70pur03BOb79I" alt=""><figcaption></figcaption></figure>

Click **+ Rule**, set your condition, provide alternate configuration for that condition, and click **Save**.

<figure><img src="/files/yPqCrs42RMcHZ1UlROZP" alt=""><figcaption></figcaption></figure>

## Experiment on your AI configuration

Go to the **Flags** view in the dashboard, and select the flag with your AI configuration from the left sidebar. Click the arrow (**>**) to view each subfield in the sidebar, and select the field you want to add a targeting rule to.

<figure><img src="/files/QLH4TTcnputljzdJxv8g" alt=""><figcaption></figcaption></figure>

Click **+ Experiment**. In the dropdown, select **New experiment**.

<figure><img src="/files/ck1Ct41AO3HueFiFHBY3" alt=""><figcaption></figcaption></figure>

Enter a name for your experiment and click **Create**.

<figure><img src="/files/dhrApFPN1z8iwKIAvfu5" alt=""><figcaption></figcaption></figure>

Click **Insert** and update the **Test** variant of your content.

<figure><img src="/files/ekgqtS4qycj4KDaasBHD" alt=""><figcaption></figcaption></figure>

Review your changes in the **Diff** view and click **Save**.

<figure><img src="/files/pmgWON8P3uHWNHbnqf30" alt=""><figcaption></figcaption></figure>

Once you've [analyzed your experiment results](/experimentation/guide.md#analyze-experiment-results) and decided on a winning variant, go to the **Flags** view and select your flag. Click the options button (⋯) next to the variant you want to ship and select **Ship variant**, then click **Save**.

<figure><img src="/files/iJ5MU8RQZoiFShIIVRJi" alt=""><figcaption></figcaption></figure>

## Next steps

* Run a [multivariate test](/concepts/multivariate-tests.md) to find the best combination of model choice, prompts, and settings to optimize key metrics like cost, latency, or user satisfaction.
* Set up an [AI loop](/concepts/ai-loops.md) to automatically optimize AI configuration for each unique user to optimize key metrics.
* Extend your schema to support more complex AI configuration, e.g. prompt chains.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.hypertune.com/ai-configuration/guide.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
