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

# OpenAI

In this guide, we will show how to send users' interactions with an OpenAI model to Nebuly's platform.

Before getting started, you would need two API keys:

* Your OpenAI key
* Nebuly authentication key

<Accordion title="How to get a Nebuly API Key">
  - Head to ⚙️ settings and navigate to “project settings”;
  - Create a new project (if you don’t have one already) and give it a name (e.g. Internal chatbot);
  - Copy the nebuly `default_key` that has been assigned to the project.
</Accordion>

<Tabs>
  <Tab title="Typescript">
    ```typescript theme={null}
    import { NebulySdk } from "@nebuly-ai/nebuly-js-sdk"
    import { OpenAI } from "openai";

    const openai = new OpenAI({
    apiKey: process.env['OPENAI_API_KEY'], // This is the default and can be omitted
    });

    async function main() {
        const nebulySdk = new NebulySdk('NEBULY_API_KEY');
        const modelInputs: OpenAI.Chat.ChatCompletionCreateParams = {
            messages: [{ role: 'user', content: 'Say this is a test' }],
            model: 'gpt-3.5-turbo',
        }
        const startTime = new Date();
        const chatCompletion = await openai.chat.completions.create(modelInputs);
        const endTime = new Date();
        
        nebulySdk.sendOpenAIInteraction(
            modelInputs['messages'],
            chatCompletion.choices[0].message.content as string,
            modelInputs['model'] as string,
            startTime,
            endTime,
            '<YOUR_USER_ID>'
        );
    }

    main();
    ```
  </Tab>
</Tabs>

Below you can find a detailed explanation of the parameters:

<ParamField path="input" type="string" required>
  Input prompt from the user
</ParamField>

<ParamField path="output" type="string" required>
  Output from the LLM model
</ParamField>

<ParamField path="time_start" type="string" required>
  When the end-user request process started
</ParamField>

<ParamField path="time_end" type="string" required>
  When the end-user request process ended
</ParamField>

<ParamField path="end_user" type="string" required>
  An id or username uniquely identifying the end-user. We recommend hashing their username or email address, in order to avoid sending us any identifying information.
</ParamField>

<ParamField path="model" type="string" required>
  The LLM model you are using. Please note that this is needed if you want to visualize the cost of your requests. Now we support costs only for OpenAI models, cost of other providers coming soon.
</ParamField>

<ParamField path="history" type="array">
  History is an array of tuples of input and output, representing the entire conversation. It should be structured as the example below:

  ```javascript theme={null}
  history = [
      ["input_1", "output_1"],
      ["input_2", "output_2"]
  ]
  ```

  In this format, `input_*` and `output_*` stand for the input and output of each interaction. So, `input_1` and `output_1` are the input and output of the first interaction, `input_2` and `output_2` are for the second interaction, and so on.
</ParamField>

<ParamField path="tags" type="object">
  Tag user interactions by adding key-value pairs using this parameter. Each key represents the tag name, and the corresponding value is the tag value.

  For example, if you want to tag an interaction with the model version used to reply to user input, provide it as an argument for tags, e.g. `{version: "v1.0.0"}`. You have the flexibility to define custom tags, making them available as potential filters on the Nebuly platform.
</ParamField>

You can find all the API details in the [API documentation](/tracking/api-reference/events/post-events-interaction-v1).
