decthings

Model / createState


Create a new model state by calling the createModelState function on the model. The created state will be added to the model's state storage.

Request parameters

{
    /** The model's id. */
    modelId: string,
    /** Name of the new state. */
    name: string,
    /** Parameters to provide to the createModelState function on the running model. */
    params: DecthingsParameterProvider[],
    /**
     * Allows your model to access to files and state of these additional models. Can be useful for merging models
     * together.
     */
    mountModels?: {
        /** Id of the other model to mount. */
        modelId: string,
        /** Specifies which state on the other model to use. Defaults to the active state. */
        stateId?: string,
        /**
         * If specified, this snapshot on the other model will be used. Cannot be used together with stateId, as the state
         * in the snapshot will be used if snapshotId is specified.
         */
        snapshotId?: string
    }[],
    /** Which launcher to use for running the operation. */
    executionLocation: {
        type: 'persistentLauncher',
        persistentLauncherId: string
    } | {
        type: 'temporaryLauncher',
        spec: LauncherSpec
    }
}

Where "DecthingsParameterProvider" is defined as:

export type DecthingsParameterProvider = {
    name: string,
    data: {
        type: 'dataset',
        datasetId: string,
        datasetKey: string
    } | {
        type: 'data',
        data: DecthingsTensor[]
    }
}

Response

{
    /** If successful. One of "result" and "error" will be present. */
    result?: {
        /** One of failed or success will be present */
        failed?: {
            durations: {
                total: number,
                createLauncher?: number,
                codeStartup?: number,
                createState?: number
            },
            error: {
                code: 'launcher_terminated' | 'cancelled' | 'server_overloaded' | 'invalid_executable_file' | 'read_executable_file_failed' | 'unknown'
            } | {
                code: 'max_duration_exceeded',
                at: 'codeStartup' | 'createState'
            } | {
                code: 'code_terminated',
                exitCode?: number,
                signal?: string,
                oom: boolean
            } | {
                code: 'exception',
                at: 'codeStartup' | 'createState',
                exceptionDetails?: string
            }
        },
        success?: {
            durations: {
                total: number,
                createLauncher?: number,
                codeStartup?: number,
                createState: number
            },
            stateId: string
        }
    },

    /** If failed */
    error?: {
        code: 'model_not_found' | 'model_to_mount_not_found' | 'state_for_model_to_mount_not_found' | 'snapshot_for_model_to_mount_not_found' | 'persistent_launcher_not_found' | 'snapshot_no_longer_exists' | 'access_denied' | 'quota_exceeded' | 'bad_credentials' | 'too_many_requests' | 'payment_required' | 'unknown'
    } | {
        code: 'dataset_not_found',
        datasetId: string
    } | {
        code: 'dataset_key_not_found',
        datasetId: string,
        datasetKey: string
    } | {
        code: 'invalid_parameter',
        parameterName: string,
        reason: string
    }
}

Example

Following the installation guide to setup the Decthings API for TypeScript. Add your parameters to the following code and run it in Node.js, or in a browser by using a bundler.

The code reads your API key from file. Create an API key and save it to the file "auth.txt". Keep your key safe!

import * as fs from 'fs'
import { DecthingsClient } from '@decthings/api-client'

let apiKey = fs.readFileSync('./auth.txt').toString().trim()
let client = new DecthingsClient({ apiKey })

async function main() {
    try {
        let response = await client.model.createState({
            modelId: /* Add modelId here */,
            name: /* Add name here */,
            params: /* Add params here */,
            executionLocation: /* Add executionLocation here */
        })
        if (result.error) {
            // Decthings sent us an error
            console.log(response.error)
        } else {
            // Success!
            console.log(response.result)
        }
    }
    catch (e) {
        // Client throws an error on connection issues. The function may or may not have succeded
        console.log(e)
    }
}
main()

Product

Company

Get going!

Sign up

This website uses cookies to enhance the experience.

Learn more