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

# Ottic SDK

> Learn how to use the Ottic SDK to manage and use published prompts in your applications

## Setup

Follow these steps to install and configure the Ottic SDK:

<Steps>
  <Step title="Install Ottic">
    Install the Ottic Node.js SDK.

    <CodeGroup>
      ```bash npm theme={null}
      npm install ottic
      ```

      ```bash yarn theme={null}
      yarn add ottic
      ```
    </CodeGroup>
  </Step>

  <Step title="Obtain Your Ottic API Key">
    Visit the [Integrations](https://app.ottic.ai/integrations) page to copy your Ottic API key.
    <Note>This key is required to authenticate and use Ottic in your application.</Note>
  </Step>

  <Step title="Integrate a Published Prompt">
    Use the snippet below to set up the Ottic SDK and begin working with a published prompt in your application:

    <CodeGroup>
      ```typescript theme={null}
      import { OtticAI } from 'ottic';

      const ottic = new OtticAI({ apiKey: OTTIC_API_KEY });

      ```
    </CodeGroup>
  </Step>
</Steps>

## Using a published prompt in production

Ottic allows you to generate responses from LLM with your prompt in your application.
Below are three use cases demonstrating how to generate responses with published prompts or render prompt text.

### 1. Generate a response using a prompt

This snippet demonstrates how to use a published prompt with variable placeholders to generate a response from the model:

<CodeGroup>
  ```typescript typescript theme={null}
  import { OtticAI } from 'ottic';

  const ottic = new OtticAI({ apiKey: OTTIC_API_KEY });

  const response = await ottic.chat.complete.create({
    promptId: 'YOUR_PROMPT_ID', // Replace with your published prompt ID
    variables: {
      variable: "dataset variable",
      variable1: "dataset variable1",
      variable2: "dataset variable2",
    },
    messages: [
      {
        role: 'user',
        content: "I want to buy a new insurance. I need help!",
      },
    ],
    metadata: {
      "userId": "METADATA_USER_ID",
      "userEmail": "USER@EMAIL.COM",
    },
    chainId: "CHAIN_ID",
    tags: ["TAG1", "TAG2"],
  });

  ```
</CodeGroup>

<ParamField path="promptId" type="string" required>
  The ID of the published prompt you want to use.
</ParamField>

<ParamField path="variables" type="object">
  Are the variables you want to use in your prompt. Without variables the prompt will be used as is.
</ParamField>

<ParamField path="messages" type="array">
  A list of messages comprising the conversation so far. If messages are not provided, prompt will be used as is.
</ParamField>

<ParamField path="metadata" type="object">
  Metadata is an object that contains additional information about the request.
</ParamField>

<ParamField path="chainId" type="string">
  Chain ID is an identifier for the chain of requests and responses.
</ParamField>

<ParamField path="tags" type="array">
  Tags is an array of strings that contains tags for the request.
</ParamField>

<Note>`metadata`, `chainId`, `tags` - are optional parameters to your request to monitor your requests and responses.</Note>
<Note>`response` will contain the output generated by the LLM based on the configuration of your Ottic prompt.</Note>
This snippet demonstrates how to request a response using the selected prompt settings.\
You can now update the LLM configuration directly in Ottic and generate responses without modifying your code.

### 2. Retrieve a rendered prompt with variable replacements

To fetch a prompt with placeholders replaced by specified variable values, use the following code:

<CodeGroup>
  ```typescript typescript theme={null}
  import { OtticAI } from 'ottic';

  const ottic = new OtticAI({ apiKey: OTTIC_API_KEY });
  const livePrompt = await ottic.prompts.render({
    promptId: 'YOUR_PROMPT_ID', 
    variables: {
      variable: "dataset variable",
      variable1: "dataset variable1",
      variable2: "dataset variable2",
    },
  });
  ```
</CodeGroup>

<ParamField path="promptId" type="string" required>
  The ID of the published prompt you want to use.
</ParamField>

<ParamField path="variables" type="object">
  Are the variables you want to use in your prompt. Without variables the prompt will be used as is.
</ParamField>

If any variables are missing, they will remain as placeholders in the returned prompt.

### 3. Retrieve a Prompt with Placeholders Intact

To retrieve a prompt without any variable replacements, use this snippet:

<CodeGroup>
  ```typescript theme={null}
  import { OtticAI } from 'ottic';

  const ottic = new OtticAI({ apiKey: OTTIC_API_KEY });
  const livePrompt = await ottic.prompts.render({promptId: 'YOUR_PROMPT_ID'});
  ```
</CodeGroup>

This will return original prompt without modifications.
