# Inference

## Quickstart

To read all inferences for a patient with MRN `$PATIENT_MRN` and model ID `$MODEL_ID` with username `$USERNAME` and private key filename `$PRIVATE_KEY_FILENAME`, run:

{% tabs %}
{% tab title="🐍 Python" %}

```python
from client_sdk import InferenceAPIClient

async with InferenceAPIClient(
    username="$USERNAME",
    private_key_filename="$PRIVATE_KEY_FILENAME",
) as client:
    inferences = await client.get_inferences(
        model_id="$MODEL_ID",
        patient_mrn="$PATIENT_MRN",
    )
```

{% endtab %}

{% tab title="🟦 TS/JS" %}

```javascript
import { InferenceAPIClient } from 'bunkerhill-inference-api/client';

const client = new InferenceAPIClient('$USERNAME', '$PRIVATE_KEY_FILENAME');

const inferences = await client.getInferences(
  '$MODEL_ID',
  '$PATIENT_MRN',
);
```

{% endtab %}
{% endtabs %}

## `InferenceAPIClient` Reference

{% tabs %}
{% tab title="🐍 Python" %}

### Constructor

#### Method signature

```python
def __init__(
    self,
    username: str,
    private_key_filename: Optional[str] = None,
    private_key_string: Optional[str] = None,
    base_url: str = 'https://api.bunkerhillhealth.com/',
) -> None:
    ...
```

#### Parameters

* `username` (`str`): The username to authenticate the client.
* `private_key_filename` (`Optional[str]`): Filename of the RSA private key.
* `private_key_string` (`Optional[str]`): The RSA private key as a string.
* `base_url` (`str`, has a default): The base URL of the Inference API. Defaults to '<https://api.bunkerhillhealth.com/>'.

**Notes**

* At least one of `private_key_filename` or `private_key_string` must be provided.

***

### `get_inferences`

Gets a list of `Inference` objects for a given patient and a given model from the Inference API. Must be called from an async context.

{% hint style="info" %}
Hint: The `get_inferences` method is asynchronous. To make use of this method from a synchronous application, calls to the `InferenceAPIClient` can be wrapped in `asyncio.run()`.
{% endhint %}

#### Method signature

<pre class="language-python"><code class="lang-python">def get_inferences(
<strong>    self,
</strong>    model_id: str,
    patient_mrn: str,
) -> List[Inference]:
    ...
</code></pre>

#### Parameters

* `model_id` (`str`): The model ID of the model.
* `patient_mrn` (`str`): The medical record number (MRN) of the patient.

#### Returns

`List[Inference]`: A list of JSON Dicts, one for each inference. See the [Inference API documentation](/software/apis/inference-api.md#inference-json-format) for more details on the format of these Dicts.

**Notes**

* You must have authorization to the specified `model_id`. If not, a `403` error will be raised.
* Only inferences corresponding to institutions that you are authorized to will be returned.
  {% endtab %}

{% tab title="🟦 TS/JS" %}

### Constructor

#### Method signature

```typescript
constructor(
  username: string,
  privateKeyFilename?: string,
  privateKeyString?: string,
  baseUrl: string = 'https://api.bunkerhillhealth.com/',
) {}
```

#### Parameters

* `username` (`string`): The username to authenticate the client.
* `privateKeyFilename` (`string`, optional): Filename of the RSA private key.
* `privateKeyString` (`string`, optional): The RSA private key as a string.
* `baseUrl` (`string`, has a default): The base URL of the Inference API. Defaults to '<https://api.bunkerhillhealth.com/>'.

**Notes**

* At least one of `privateKeyFilename` or `privateKeyString` must be provided.

***

### `getInferences`

Fetches a list of `Inference` objects for a given patient and a given model from the Inference API. Must be called from an async context.

#### Method signature

```typescript
async getInferences(
  modelId: string,
  patientMrn: string,
): Promise<Inference[]> {}
```

#### Parameters

* `modelId` (`str`): The model ID of the model.
* `patientMrn` (`str`): The medical record number (MRN) of the patient.

#### Returns

`Promise<Inference[]>`: A list of JSON Dicts, one for each inference. See [Inference JSON Format](/software/apis/inference-api.md#inference-json-format) for more details on the format of these Dicts.

**Notes**

* You must have authorization to the specified `modelId`. If not, a `403` error will be raised.
* Only inferences corresponding to institutions that you are authorized to will be returned.
  {% endtab %}
  {% endtabs %}


---

# 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.bunkerhillhealth.com/software/sdks/client-sdk/client-sdk-usage/inference.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.
