> ## 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.

# Servers

export const GCell = ({children, className}) => <div className={`grid-table-cell ${className || ""}`} role="cell">
    {children}
  </div>;

export const GTH = ({children, className}) => <div className={`grid-table-th ${className || ""}`} role="columnheader">
    {children}
  </div>;

export const GRow = ({children}) => <div className="grid-table-row" role="row">{children}</div>;

export const GBody = ({children}) => <div className="grid-table-body" role="rowgroup">{children}</div>;

export const GHead = ({children}) => <div className="grid-table-head" role="rowgroup">{children}</div>;

export const GTable = ({children, className, cols}) => <div className={`grid-table not-prose overflow-hidden rounded-2xl ${className || ""}`} style={{
  "--grid-table-cols": cols
}} role="table">
    {children}
  </div>;

The `.servers` accessor provides methods for creating, listing, starting, and stopping servers.

<Note>
  Some methods like `.match()` and the parameter classes below are backend-specific and may not be available on all backends.
</Note>

<GTable cols="30% 30% 40%">
  <GHead>
    <GRow>
      <GTH>Method</GTH>
      <GTH>Return</GTH>
      <GTH>Description</GTH>
    </GRow>
  </GHead>

  <GBody>
    <GRow>
      <GCell>`.list()`</GCell>
      <GCell>`List[Server]`</GCell>
      <GCell>List running servers</GCell>
    </GRow>

    <GRow>
      <GCell>`.get('<server-id>')`</GCell>
      <GCell>`Server`</GCell>
      <GCell>Look up a running server by name or UUID</GCell>
    </GRow>

    <GRow>
      <GCell>`.match()`</GCell>
      <GCell>`Server`</GCell>
      <GCell>Find a running server matching configuration</GCell>
    </GRow>

    <GRow>
      <GCell>`.create(model, extra_options=None)`</GCell>
      <GCell>`Server`</GCell>
      <GCell>Create new server configuration</GCell>
    </GRow>

    <GRow>
      <GCell>`.start('<server-id>')`</GCell>
      <GCell>`None`</GCell>
      <GCell>Start the API server</GCell>
    </GRow>

    <GRow>
      <GCell>`.status('<server-id>')`</GCell>
      <GCell>`str`</GCell>
      <GCell>Get server status</GCell>
    </GRow>

    <GRow>
      <GCell>`.stop('<server-id>')`</GCell>
      <GCell>`None`</GCell>
      <GCell>Stop a running server</GCell>
    </GRow>

    <GRow>
      <GCell>`.delete('<server-id>')`</GCell>
      <GCell>`None`</GCell>
      <GCell>Remove server configuration</GCell>
    </GRow>
  </GBody>
</GTable>

## Creating servers

The `.create()` method creates a new server configuration. By default, it downloads the model file (if not already downloaded) and selects a random, unused port for the server.

<Note>
  If a server with the specified configuration is already running, the existing configuration is returned, and no new server is created.
</Note>

Create servers using one of the following approaches:

<Tabs>
  <Tab title="Using model string reference">
    ```py theme={null}
    from anaconda_ai import AnacondaAIClient

    client = AnacondaAIClient()
    server = client.servers.create('OpenHermes-2.5-Mistral-7B/Q4_K_M')
    ```
  </Tab>

  <Tab title="Using QuantizedFile object">
    ```py theme={null}
    from anaconda_ai import AnacondaAIClient

    client = AnacondaAIClient()
    quant = client.models.get('OpenHermes-2.5-Mistral-7B').get_quantization('Q4_K_M')
    server = client.servers.create(quant)
    ```
  </Tab>
</Tabs>

<Tip>
  To look up an existing running server rather than create one, use `.get()`. Pass the server's name or UUID as a string:

  ```py theme={null}
  server = client.servers.get('my-server-name')
  ```
</Tip>

## Server configuration parameters

The `.create()` method accepts an `extra_options` parameter to customize server behavior:

```py theme={null}
def create(
    model: str,
    download_if_needed: bool = True,
    extra_options: Optional[Dict[str, Any]] = None,
    show_progress: bool = True,
    console: Optional[Console] = None
) -> Server:
```

<Note>
  Server configuration options are backend-specific. The parameters below apply to the `ai-navigator` and `anaconda-desktop` backends.
</Note>

Common server options include:

<GTable cols="30% 20% 50%">
  <GHead>
    <GRow>
      <GTH>Parameter</GTH>
      <GTH>Type</GTH>
      <GTH>Description</GTH>
    </GRow>
  </GHead>

  <GBody>
    <GRow>
      <GCell>`host`</GCell>
      <GCell>`str`</GCell>
      <GCell>Server host address (default: "127.0.0.1")</GCell>
    </GRow>

    <GRow>
      <GCell>`port`</GCell>
      <GCell>`int`</GCell>
      <GCell>Server port (0 for random unused port)</GCell>
    </GRow>

    <GRow>
      <GCell>`ctx_size`</GCell>
      <GCell>`int`</GCell>
      <GCell>Context window size</GCell>
    </GRow>

    <GRow>
      <GCell>`n_gpu_layers`</GCell>
      <GCell>`int`</GCell>
      <GCell>Number of layers to offload to GPU</GCell>
    </GRow>

    <GRow>
      <GCell>`main_gpu`</GCell>
      <GCell>`int`</GCell>
      <GCell>Main GPU device ID</GCell>
    </GRow>

    <GRow>
      <GCell>`temp`</GCell>
      <GCell>`float`</GCell>
      <GCell>Sampling temperature</GCell>
    </GRow>

    <GRow>
      <GCell>`top_k`</GCell>
      <GCell>`int`</GCell>
      <GCell>Top-k sampling parameter</GCell>
    </GRow>

    <GRow>
      <GCell>`top_p`</GCell>
      <GCell>`float`</GCell>
      <GCell>Top-p (nucleus) sampling parameter</GCell>
    </GRow>

    <GRow>
      <GCell>`batch_size`</GCell>
      <GCell>`int`</GCell>
      <GCell>Batch size for processing</GCell>
    </GRow>

    <GRow>
      <GCell>`embedding`</GCell>
      <GCell>`bool`</GCell>
      <GCell>Enable embedding mode for embedding models</GCell>
    </GRow>

    <GRow>
      <GCell>`jinja`</GCell>
      <GCell>`bool`</GCell>
      <GCell>Enable Jinja template processing</GCell>
    </GRow>
  </GBody>
</GTable>

For example, to create a server with custom configuration:

```py theme={null}
server = client.servers.create(
    'OpenHermes-2.5-Mistral-7B/Q4_K_M',
    extra_options={
        'host': '127.0.0.1',
        'port': 9999,
        'ctx_size': 4096,
        'n_gpu_layers': 20,
        'temp': 0.7,
        'top_p': 0.9
    },
    download_if_needed=False
)
```

## Managing servers

New servers are not automatically started when their configuration is created. You can start or stop a server using the following methods:

<Tabs>
  <Tab title="Using the server object">
    ```python theme={null}
        server.start()
        server.stop()
    ```
  </Tab>

  <Tab title="Using the .servers accessor">
    ```python theme={null}
        # Start or stop the server object returned from .create
        client.servers.start(server)
        client.servers.stop(server)
    ```
  </Tab>

  <Tab title="Using server as a context manager">
    This approach automatically starts and stops the server:

    ```python theme={null}
        with client.servers.create('OpenHermes-2.5-Mistral-7B/Q4_K_M') as server:
            openai_client = server.openai_client()
            # Make requests to the server
    ```
  </Tab>
</Tabs>

## Server attributes

<GTable cols="30% 70%">
  <GHead>
    <GRow>
      <GTH>Attribute</GTH>
      <GTH>Description</GTH>
    </GRow>
  </GHead>

  <GBody>
    <GRow>
      <GCell>`.url`</GCell>
      <GCell>Full server URL (example: `http://127.0.0.1:8000`)</GCell>
    </GRow>

    <GRow>
      <GCell>`.openai_url`</GCell>
      <GCell>URL with `/v1` for OpenAI compatibility</GCell>
    </GRow>

    <GRow>
      <GCell>`.openai_client()`</GCell>
      <GCell>Pre-configured OpenAI client</GCell>
    </GRow>

    <GRow>
      <GCell>`async_openai_client()`</GCell>
      <GCell>Pre-configured async OpenAI client</GCell>
    </GRow>
  </GBody>
</GTable>
