> For the complete documentation index, see [llms.txt](https://docs.akkio.com/akkio-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.akkio.com/akkio-docs/endpoints-and-schemas/additional-libraries/node.js.md).

# Node.js Library

Node.js library for Akkio

## API Keys

As noted in the code samples below, you must get your API keys and copy them into your API code. Those can be found under the [team settings page](https://app.akkio.com/team-settings) at the bottom of the Akkio app.

<figure><img src="https://71333621-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MUiovvmaDi_ad2DYdZ4%2Fuploads%2FYp8bQSrSBDioMANAQeCb%2FScreenshot%202023-05-18%20at%2009.55.46.png?alt=media&amp;token=59d35f6a-2a68-45a7-9c87-f312bbaf615e" alt=""><figcaption></figcaption></figure>

## Installation

```bash
npm install --save akkio
```

## Example Usage

```bash
# get your API key at https://app.akkio.com/team-settings
const akkio = require('akkio')('your API key');

(async () => {
  # create a new dataset
  let newDataset = await akkio.createDataset('my new dataset');

  # populate it with some toy data
  let rows = [];
  for (var i = 0; i < 1000; i++) {
    let x = Math.random();
    rows.push({
      'x': x,
      'value larger than 0.5': x > 0.5,
    });
  }
  await akkio.addRowsToDataset(newDataset.dataset_id, rows);

  # train a model
  let model = await akkio.createModel(newDataset.dataset_id, ['value larger than 0.5'], [], {
    duration: 1
  });

  # field importance
  for (let field in model.field_importance) {
    console.log('field:', field, 'importance:', model.field_importance[field]);
  }

  # model stats
  for (let field of model.stats) {
    for (let outcome of field) {
      console.log(outcome);
    }
  }

  # use the trained model to make predictions
  let predictions = await akkio.makePrediction(model.model_id, [{
    'x': 0.25
  }, {
    'x': 0.75
  }], {
    explain: true
  });
  console.log(predictions);

})();
```

## Datasets

### createDataset(dataset\_name)

Create a new empty dataset.

| input         | description                             |
| ------------- | --------------------------------------- |
| dataset\_name | The name of your newly created dataset. |

###

### addRowsToDataset(dataset\_id, rows)

Add rows to a dataset.

| input       | description                                                                                                                                 |
| ----------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
| dataset\_id | A dataset id                                                                                                                                |
| rows        | <p>An array of rows to be added to the dataset in the following form: </p><p>\[{ "field 1": "data", "field 2": "data" }, { ... }, ... ]</p> |

###

### getDatasets()

Get all datasets in your organization.

###

### getDataset(dataset\_id)

Get a dataset.

| input       | description  |
| ----------- | ------------ |
| dataset\_id | A dataset id |

### parseDataset(dataset\_id)

Recalculate the field types for a dataset.

| input       | description  |
| ----------- | ------------ |
| dataset\_id | A dataset id |

###

### deleteDataset(dataset\_id)

Delete a dataset.

| input       | description  |
| ----------- | ------------ |
| dataset\_id | A dataset id |

## Models

### getModels()

Get all models in your organization.

### deleteModel(model\_id)

Delete a model in your organization.

| input     | description |
| --------- | ----------- |
| model\_id | A model id  |

###

### createModel(dataset\_id, predict\_fields, ignore\_fields, params)

Create a model (requires a dataset).

| input           | description                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| dataset\_id     | A dataset id                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| predict\_fields | An array of field names to predict (case sensitive)                                                                                                                                                                                                                                                                                                                                                                                          |
| ignore\_fields  | An array of field names to ignore (case sensitive) (optional)                                                                                                                                                                                                                                                                                                                                                                                |
| params          | <p>A dict with default value of:</p><p><code>{</code><br>    <code>"duration": 10,</code></p><p>    <code>"extra\_attention: false,</code></p><p>    <code>"force": false</code><br><code>}</code></p><p><code>duration</code> is the duration in seconds to be used for model training.</p><p><code>extra\_attention</code> can be enabled to help with predicting rare cases</p><p><code>force</code> forces a new model to be created</p> |

{% hint style="info" %}
Sometimes creating models can take a while, especially if this is the first time creating a model on this dataset. **createModel** is idempotent and can be called multiple times with the same parameters.
{% endhint %}

###

### makePrediction(model\_id, data)

Make a prediction using your model and new data.

| input     | description                                                                                                                      |
| --------- | -------------------------------------------------------------------------------------------------------------------------------- |
| model\_id | A model id                                                                                                                       |
| data      | <p>An array of rows to be predicted in the following form: </p><p>\[{ "field 1": "data", "field 2": "data" }, { ... }, ... ]</p> |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.akkio.com/akkio-docs/endpoints-and-schemas/additional-libraries/node.js.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
