# OpenAI

`openai` is the OpenAI chat model provider. It uses the `OPENAI_API_...` environment variables.

1. [Upgrade your account](https://platform.openai.com/settings/organization/billing/overview) to get access to the models. You will get 404s if you do not have a paying account.

2. Create a new secret key from the [OpenAI API Keys portal](https://platform.openai.com/api-keys).

3. Update the `.env` file with the secret key.

   .env

   ```txt
   OPENAI_API_KEY=sk_...
   ```

4. Find the model you want to use from the [OpenAI API Reference](https://platform.openai.com/docs/models/gpt-4o) or the [OpenAI Chat Playground](https://platform.openai.com/playground/chat).

   ![Screenshot of a user interface with a sidebar on the left and a dropdown menu titled 'Chat' with various options for AI models. The 'gpt-4o' option is highlighted and selected with a checkmark, described as 'High-intelligence flagship model for complex, multi-step tasks'.
   ](/genaiscript/_astro/openai-model-names.4qOpyXrM_Eb2fp.webp)

5. Set the `model` field in `script` to the model you want to use.

   ```js
   script({
       model: "openai:gpt-4o",
       ...
   })
   ```

Default Model Configuration

Use `GENAISCRIPT_MODEL_LARGE` and `GENAISCRIPT_MODEL_SMALL` in your `.env` file to set the default model and small model.

```txt
GENAISCRIPT_MODEL_LARGE=openai:gpt-4o
GENAISCRIPT_MODEL_SMALL=openai:gpt-4o-mini
```

## Logging

[Section titled “Logging”](#logging)

You can enable the `genaiscript:openai` and `genaiscript:openai:msg` [logging namespaces](/genaiscript/reference/scripts/logging) for more information about the requests and responses:

### Aliases

The following model aliases are attempted by default in GenAIScript.

| Alias            | Model identifier       |
| ---------------- | ---------------------- |
| large            | gpt-4.1                |
| small            | gpt-4.1-mini           |
| tiny             | gpt-4.1-nano           |
| vision           | gpt-4.1                |
| vision\_small    | gpt-4.1-mini           |
| embeddings       | text-embedding-3-small |
| reasoning        | o1                     |
| reasoning\_small | o3-mini                |
| transcription    | whisper-1              |
| speech           | tts-1                  |
| image            | gpt-image-1            |
| intent           | gpt-4.1-mini           |