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

# Quickstart

> Wrap an OpenAI client and run your first guarded request.

This quickstart gives you one working Averta-protected OpenAI request. Use the JavaScript or Python snippet that matches your app.

## 1. Create a Policy and API Keys

Create a [policy](/dashboard/policies) in the [Averta Dashboard](https://dashboard.averta.io), then create an [Averta API key](/dashboard/api-keys) with that policy attached. You also need a normal OpenAI API key.

<Warning>
  A key without an attached policy is not a guarded setup. Store the Averta secret when you create it; the dashboard does not show it again later.
</Warning>

## 2. Install Packages

<CodeGroup>
  ```bash npm theme={null}
  npm install openai @averta-security/sdk-openai
  ```

  ```bash yarn theme={null}
  yarn add openai @averta-security/sdk-openai
  ```

  ```bash pnpm theme={null}
  pnpm add openai @averta-security/sdk-openai
  ```

  ```bash Python source theme={null}
  python3 -m venv .venv
  . .venv/bin/activate
  python3 -m pip install "openai>=2" -e packages/python-core -e packages/python-openai
  ```
</CodeGroup>

<Warning>
  Python support is source-install only until `averta-openai` is published to PyPI. Run the Python install command from the SDK repository.
</Warning>

## 3. Set Environment Variables

```bash theme={null}
export OPENAI_API_KEY="your-openai-key"
export AVERTA_API_KEY="your-averta-key"
```

The Averta wrapper reads `AVERTA_API_KEY` from the environment. Pass a key in code only when you need to override the environment for a specific client.

## 4. Create a Quickstart File

<CodeGroup>
  ```javascript Node.js theme={null}
  import OpenAI from "openai";
  import { wrapOpenAI } from "@averta-security/sdk-openai";

  function readEnv(name) {
    const value = process.env[name];

    if (!value) {
      throw new Error(`Missing required environment variable: ${name}`);
    }

    return value;
  }

  const client = wrapOpenAI(
    new OpenAI({
      apiKey: readEnv("OPENAI_API_KEY"),
    })
  );

  const response = await client.responses.create({
    model: process.env.OPENAI_MODEL ?? "gpt-5.4-mini",
    input: "Write one sentence explaining what a password reset link is.",
  });

  console.log("\nModel output:");
  console.log(response.output_text);
  ```

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

  from openai import OpenAI
  from averta_openai import wrap_openai


  def read_env(name):
      value = os.environ.get(name)

      if not value:
          raise RuntimeError(f"Missing required environment variable: {name}")

      return value


  client = wrap_openai(OpenAI(api_key=read_env("OPENAI_API_KEY")))

  response = client.responses.create(
      model=os.environ.get("OPENAI_MODEL", "gpt-5.4-mini"),
      input="Write one sentence explaining what a password reset link is.",
  )

  print("\nModel output:")
  print(response.output_text)
  ```
</CodeGroup>

## 5. Run It

<CodeGroup>
  ```bash Node.js theme={null}
  node quickstart.mjs
  ```

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

With a policy that allows the request, you should see model output:

```text theme={null}
Model output:
A password reset link lets a verified user choose a new password for their account.
```

The exact model text will vary. The important part is that Averta runs checkpoint decisions before your application returns the result.

## What Happened

* The wrapper sent a [request checkpoint](/concepts/checkpoints#request) to Averta before calling OpenAI.
* Averta used the [policy attached to your API key](/concepts/policies) to decide what should happen.
* If policy returned `block`, the SDK would throw before the OpenAI request.
* OpenAI generated a non-streaming final answer.
* The wrapper sent an output checkpoint to Averta before returning the response.
* The SDK generated `requestId` and `traceId` automatically so decisions can be found in dashboard events.

## Add Tools Next

When your agent passes tools, Averta can also [restrict tool exposure](/dashboard/tool-exposure-policy) before the provider sees the tool list and screen [tool results](/concepts/checkpoints#tool-result) before they return to the model.

<CodeGroup>
  ```javascript Node.js theme={null}
  const tools = [
    {
      type: "function",
      name: "search_docs",
      description: "Search internal support documentation.",
      strict: true,
      parameters: {
        type: "object",
        properties: {
          query: { type: "string" },
        },
        required: ["query"],
        additionalProperties: false,
      },
    },
  ];

  const responseWithTools = await client.responses.create({
    model: process.env.OPENAI_MODEL ?? "gpt-5.4-mini",
    input: "Search the docs for password reset guidance.",
    tools,
  });
  ```

  ```python Python theme={null}
  tools = [
      {
          "type": "function",
          "name": "search_docs",
          "description": "Search internal support documentation.",
          "strict": True,
          "parameters": {
              "type": "object",
              "properties": {"query": {"type": "string"}},
              "required": ["query"],
              "additionalProperties": False,
          },
      }
  ]

  response_with_tools = client.responses.create(
      model=os.environ.get("OPENAI_MODEL", "gpt-5.4-mini"),
      input="Search the docs for password reset guidance.",
      tools=tools,
  )
  ```
</CodeGroup>

Use [OpenAI quickstart](/openai/quickstart) for the complete tool-loop pattern.

## Next Steps

<CardGroup cols={2}>
  <Card title="OpenAI quickstart" icon="wand-magic-sparkles" href="/openai/quickstart">
    Add tools, request context, and decision logging to an OpenAI agent loop.
  </Card>

  <Card title="Anthropic quickstart" icon="sparkles" href="/anthropic/quickstart">
    Use the same checkpoint model with Anthropic Messages.
  </Card>

  <Card title="Checkpoints" icon="shield-check" href="/concepts/checkpoints">
    Understand each Averta decision point.
  </Card>

  <Card title="Policies" icon="sliders" href="/dashboard/policies">
    Create the policy that makes runtime enforcement active.
  </Card>

  <Card title="Events" icon="activity" href="/dashboard/events">
    Find the request and output decisions in the dashboard.
  </Card>
</CardGroup>
