# OpenAI

To utilize OpenAI’s powerful models with PapertLab, you need to provide your OpenAI API key. You can do this in two ways: by setting the `OPENAI_API_KEY` environment variable or by adding the key directly through the API section of the settings page in PapertLab. Additionally, you can specify the API key via the `--openai-api-key` command line option.

#### Adding API Keys via PapertLab Settings

<figure><img src="https://323147515-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDxsCSiLtcLEhVsYJxaEU%2Fuploads%2FQ26BaaEAU9bzccvdzGxb%2Fapi.png?alt=media&#x26;token=860a196c-19d5-4b4d-b770-f273e8898459" alt=""><figcaption></figcaption></figure>

You can also connect PapertLab to OpenAI by adding your API key directly through the PapertLab settings page:

1. **Navigate to the Settings Page**: Open PapertLab and go to the settings page.
2. **Locate the API Section**: In the API section, enter your OpenAI API key in the designated field.
3. **Save Your Changes**: Click "Save" to apply the settings. PapertLab will now be connected to OpenAI using the provided API key.

This method is particularly useful if you prefer managing your keys through the user interface rather than using environment variables or command line options.

PapertLab is optimized to work seamlessly with the most popular OpenAI models, and it has been thoroughly tested and benchmarked to ensure smooth performance:

1. **Installation**: First, ensure that PapertLab is installed on your system.

   ```bash
   python -m pip install papert-lab
   ```
2. **Set the OpenAI API Key**:
   * **Mac/Linux**:

     ```bash
     export OPENAI_API_KEY=<your-api-key>
     ```
   * **Windows**:

     ```cmd
     setx OPENAI_API_KEY <your-api-key>
     ```

     *(Note: After running `setx`, restart your shell for the changes to take effect.)*
3. **Using PapertLab with OpenAI Models**:
   * **Default Model**: By default, PapertLab uses the **GPT-4o** model, which offers advanced capabilities for code editing.

     ```bash
     papertlab
     ```
   * **GPT-4 Turbo (1106)**: If you prefer to use a specific version of GPT-4 Turbo, you can do so by specifying the model.

     ```bash
     papertlab --4-turbo
     ```
   * **GPT-3.5 Turbo**: You can switch to using GPT-3.5 Turbo if needed.

     ```bash
     papertlab --35-turbo
     ```
4. **Listing Available Models**: To see all the models available from OpenAI that PapertLab can connect with, use the following command:

   ```bash
   papertlab --models openai/
   ```
5. **Using Other OpenAI Models**: If you want to use a specific OpenAI model, simply pass the model name to the `--model` option. For example, to use a specific preview version of GPT-4 Turbo, you can run:

   ```bash
   papertlab --model gpt-4-0125-preview
   ```


---

# 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.papert.in/connecting-to-llms/openai.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.
