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

# API server

export const Comments = ({children}) => {
  return <div class="my-4 px-5 py-4 overflow-hidden rounded-2xl flex gap-3 border border-zinc-500/20 bg-zinc-50/50 dark:border-zinc-500/30 dark:bg-zinc-500/10" data-callout-type="comments">
      <div class="w-4">
        <svg width="14" height="14" viewBox="0 0 640 640" fill="currentColor" xmlns="http://www.w3.org/2000/svg" class="w-5 h-5" aria-label="Comments">
            <path d="M320 112C434.9 112 528 205.1 528 320C528 434.9 434.9 528 320 528C205.1 528 112 434.9 112 320C112 205.1 205.1 112 320 112zM320 576C461.4 576 576 461.4 576 320C576 178.6 461.4 64 320 64C178.6 64 64 178.6 64 320C64 461.4 178.6 576 320 576zM280 400C266.7 400 256 410.7 256 424C256 437.3 266.7 448 280 448L360 448C373.3 448 384 437.3 384 424C384 410.7 373.3 400 360 400L352 400L352 312C352 298.7 341.3 288 328 288L280 288C266.7 288 256 298.7 256 312C256 325.3 266.7 336 280 336L304 336L304 400L280 400zM320 256C337.7 256 352 241.7 352 224C352 206.3 337.7 192 320 192C302.3 192 288 206.3 288 224C288 241.7 302.3 256 320 256z" />
        </svg>
      </div>
      <div class="text-sm prose min-w-0 w-full">
        {children}
      </div>
    </div>;
};

export const API = () => {
  return <span className="inline_icon">
      <svg class="inline" width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg">
        <g clip-path="url(#clip0_2642_98)">
          <path fill="currentColor" d="M16.9687 8.71875C18.7187 9.25 20 10.8438 20 12.75C20 15.125 18.0938 17 15.75 17H4.5C2 17 0 15 0 12.5C0 10.5625 1.25 8.90625 3 8.28125C2.96875 5.375 5.3125 3 8.25 3C9.96872 3 11.5 3.875 12.4687 5.1875C12.7813 5.09375 13.125 5 13.5 5C15.4062 5 17 6.59375 17 8.5C17 8.59375 16.9687 8.65625 16.9687 8.71875ZM15.75 15.5C17.25 15.5 18.5 14.2813 18.5 12.75C18.5 11.5625 17.6875 10.5 16.5313 10.1562L15.4062 9.8125L15.4687 8.625C15.5313 7.40625 14.4375 6.15625 12.9062 6.625L11.875 6.9375L11.25 6.0625C10.5313 5.09375 9.43752 4.5 8.25 4.5C6.1875 4.5 4.53125 6.15625 4.5 8.1875C4.5 8.3125 4.5 8.125 4.5 9.34375L3.5 9.71875C2.28125 10.125 1.5 11.25 1.5 12.5C1.5 14.1562 2.84375 15.5 4.5 15.5H15.75Z"></path>
          <path fill="currentColor" d="M5.40366 13.4H4.50366L6.14229 8.74545H7.18321L8.82413 13.4H7.92411L6.68093 9.7H6.64457L5.40366 13.4ZM5.43321 11.575H7.88775V12.2522H5.43321V11.575ZM9.43717 13.4V8.74545H11.1826C11.5402 8.74545 11.8402 8.81212 12.0826 8.94545C12.3266 9.07878 12.5107 9.26212 12.6349 9.49545C12.7607 9.72727 12.8236 9.99091 12.8236 10.2864C12.8236 10.5848 12.7607 10.85 12.6349 11.0818C12.5092 11.3136 12.3236 11.4962 12.0781 11.6295C11.8326 11.7614 11.5304 11.8273 11.1712 11.8273H10.0144V11.1341H11.0576C11.2668 11.1341 11.438 11.0978 11.5712 11.025C11.7046 10.9523 11.8031 10.8523 11.8668 10.725C11.9319 10.5977 11.9644 10.4515 11.9644 10.2864C11.9644 10.1212 11.9319 9.97576 11.8668 9.85C11.8031 9.72424 11.7039 9.62651 11.569 9.55681C11.4356 9.4856 11.2637 9.45 11.0531 9.45H10.2804V13.4H9.43717ZM14.3991 8.74545V13.4H13.556V8.74545H14.3991Z"></path>
        </g>
        <defs>
          <clipPath id="clip0_2642_98">
            <rect width="20" height="14" transform="translate(0 3)"></rect>
          </clipPath>
        </defs>
      </svg>
    </span>;
};

export const TroubleshootSolution = ({children}) => <>
    <hr className="my-3 w-full" />
    <details className="mt-3">
      <summary className="cursor-pointer font-semibold text-base mb-1">
        Solution
      </summary>
      <div className="mt-2 ml-4" data-component-part="step-content">
        {children}
      </div>
    </details>
  </>;

export const TroubleshootCause = ({children}) => <details className="mt-3 mb-2">
    <summary className="cursor-pointer font-semibold text-base mb-1">
      Cause
    </summary>
    <div className="mt-2 ml-4" data-component-part="step-content">
      {children}
    </div>
  </details>;

export const TroubleshootTitle = ({children}) => <>
    <p className="m-0 font-semibold text-xl leading-tight mb-2" role="heading" aria-level={3}>
      {children}
    </p>
    <hr className="my-3 w-full" />
  </>;

export const Troubleshoot = ({children}) => <div className="callout my-4 px-5 py-4 overflow-hidden rounded-2xl flex gap-3 border troubleshoot-admonition dark:troubleshoot-admonition" data-callout-type="troubleshoot">
    <div className="mt-0.5 w-4">
      <svg width="14" height="14" viewBox="0 0 640 640" fill="currentColor" className="w-4 h-4" aria-label="Troubleshoot">
        <path d="M541.4 162.6C549 155 561.7 156.9 565.5 166.9C572.3 184.6 576 203.9 576 224C576 312.4 504.4 384 416 384C398.5 384 381.6 381.2 365.8 376L178.9 562.9C150.8 591 105.2 591 77.1 562.9C49 534.8 49 489.2 77.1 461.1L264 274.2C258.8 258.4 256 241.6 256 224C256 135.6 327.6 64 416 64C436.1 64 455.4 67.7 473.1 74.5C483.1 78.3 484.9 91 477.4 98.6L388.7 187.3C385.7 190.3 384 194.4 384 198.6L384 240C384 248.8 391.2 256 400 256L441.4 256C445.6 256 449.7 254.3 452.7 251.3L541.4 162.6z" />
      </svg>
    </div>
    <div className="prose min-w-0 w-full">{children}</div>
  </div>;

The built-in API server enables you to run open-source large language models (LLMs) locally on your own machine. It facilitates direct interaction with your models through API calls, providing a powerful tool for testing and deploying models without the need for external cloud services. By hosting your own API server locally, you have full control over the model's behavior and maintain the privacy and security of your data.

## Understanding the API server

The API server is the core component of Anaconda AI Navigator that enables you to interact with your locally downloaded LLMs through API calls.

<Tip>
  Hover over a <Icon icon="circle-info" iconType="regular" /> tooltip to view information about the API Server's configurable <Tooltip tip="Model parameters are the weights and biases it learns during training. The more parameters a model has, the better its ability to learn, but the more tightly it will conform to its training data.">parameters</Tooltip>.
</Tip>

### Server address

Your local server address, often referred to as `localhost` or `127.0.0.1`, is the default address for the API server. It is a loopback address, meaning any network communication sent to this address will stay within the same machine, keeping your data secure and private. This is common for developing applications.

If you are working in an office network and would like to make your server accessible to other devices within the same network, you can set the server address to your machine's local IP address. These are typically private networks, meaning they're not routable on the public internet.

Setting the server address to `0.0.0.0` configures it to accept connections on all network interfaces. This can expose your server to the public internet if your network is configured to allow external connections and route traffic from external sources to your server.

### Server port

The server port tells the built-in API server where to listen for incoming traffic (that is, where to listen and pick up API requests).

For more information, see [Cloudflare's article on ports](https://www.cloudflare.com/learning/network-layer/what-is-a-computer-port/).

### API Key

Establish an API Key that must be passed as an `Authentication: Bearer` token in the header of requests made to your server.

<Accordion title="Testing your API Key">
  To test an API Key:

  1. Select <API /> **API Server** from the left-hand navigation.

  2. Enter your API Key in AI Navigator.

  3. [Load a model into the API server](/tools/ai-navigator/getting-started-ai-navigator#loading-a-model-into-the-api-server).

       <Note>
         You must use a `text-generation` type model.
       </Note>

  4. Open [Anaconda Prompt](/reference/glossary#anaconda-prompt) (Terminal on macOS/Linux) and run the following command:

       <CodeGroup>
         ```sh Anaconda Prompt theme={null}
         curl --request POST ^
             --url http://localhost:8080/completion ^
             --header 'Authorization: Bearer <API_KEY>' ^
             --header "Content-Type: application/json" ^
             --data '{
                 "prompt": "Hello, how are you?"
             }'
         ```

         ```sh Anaconda PowerShell Prompt theme={null}
         curl --request POST `
             --url http://localhost:8080/completion `
             --header 'Authorization: Bearer <API_KEY>' `
             --header "Content-Type: application/json" `
             --data '{
                 "prompt": "Hello, how are you?"
             }'
         ```

         ```sh Terminal theme={null}
         curl --request POST \
             --url http://localhost:8080/completion \
             --header 'Authorization: Bearer <API_KEY>' \
             --header "Content-Type: application/json" \
             --data '{
                 "prompt": "Hello, how are you?"
             }'
         ```
       </CodeGroup>

       <Comments>
         Replace \<API\_KEY> with the value you entered into AI Navigator.
       </Comments>

  This command will reach out to the local API servers `/completion` endpoint to interact with the model you have loaded. If you receive a response, your API Key is working. If you receive a 401 error, double check your command and try again.
</Accordion>

<Troubleshoot>
  <TroubleshootTitle>
    ### Model won't load (exit code 3221225781)
  </TroubleshootTitle>

  <TroubleshootCause>
    The model you are trying to load requires a C++ runtime environment, but Microsoft does not include one in their operating systems by default.
  </TroubleshootCause>

  <TroubleshootSolution>
    Install the Latest [Microsoft Visual C++ Redistributable Version](https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist?view=msvc-170#latest-microsoft-visual-c-redistributable-version).
  </TroubleshootSolution>
</Troubleshoot>

## Viewing API server logs

To view your server logs:

1. Open Anaconda AI Navigator.
2. Select <API /> **API Server** from the left-hand navigation.

The server logs provide information for the following metrics:

* **System information**: Provides information about your system's hardware capabilities.
* **Build information**: Provides information about the version of the API server you are using.
* **Chat template**: Shows the sequence of messaging defined for the system.
* **Server listening**: Displays the server address and port number being listened to.
* **Slot information**: Displays the number of available slots for the server. Each slot is able to manage one user API request at a time.
* **Task information**: Displays information such as time spent processing and responding to a request, the request task ID, and which slot fulfilled the task.

The API server records all incoming traffic for the currently running server and displays relevant information in the **Server Logs**.

Once the server is stopped, the log is saved to `~/Library/Logs/ai-navigator` with a timestamped filename (for example `<YYYY><MM><DD><HH><MM><SS>_api-server.log`), so you can efficiently locate specific server logs if necessary.
