Model / getModels
TypeScript
Retrieve information about models. If the requested model wasn't returned, it means that the model doesn't exist (or you don't have access to it).
Request parameters
{
/** Number of items from the results to skip. Defaults to 0. */
offset?: number,
/** Max number of items to return. Defaults to 20. */
limit?: number,
/** If specified, determines which items to retrieve. */
filter?: {
owners?: string[],
tags?: {
tag: string,
value: string
}[],
ids?: string[],
names?: string[],
searchName?: string
},
/** Specifies a field in the returned items to sort by. Defaults to "createdAt". */
sort?: string,
sortDirection?: 'asc' | 'desc'
}
Response
{
/** If successful. One of "result" and "error" will be present. */
result?: {
models: Model[],
/** The total number of models that matched the filter. */
total: number,
offset: number,
limit: number
},
/** If failed */
error?: {
code: 'bad_credentials' | 'too_many_requests' | 'payment_required' | 'unknown'
} | {
code: 'invalid_parameter',
parameterName: string,
reason: string
}
}
Where "ParameterDefinitions", "ModelState" and "Model" are defined as:
export type ParameterDefinitions = {
createState: DecthingsParameterDefinition,
train: DecthingsParameterDefinition,
evaluateInput: DecthingsParameterDefinition,
evaluateOutput: DecthingsParameterDefinition
}
export type ModelState = {
id: string,
name: string,
/** Identifiers of all the training operations that have been performed to reach this state. */
trainingOperations: string[],
createdAt: number,
beingDeleted: boolean,
state: {
key: string,
byteSize: number
}[],
mountedModels: {
modelId: string,
snapshotId?: string
}[]
}
export type Model = {
id: string,
name: string,
description: string,
publicAccess: boolean,
createdAt: number,
tags: {
tag: string,
value: string
}[],
owner: {
type: 'user',
userId: string,
username: string
} | {
type: 'organization',
organizationId: string,
organizationName: string
},
access: 'read' | 'readwrite',
beingCreated: boolean,
language: 'go' | 'javascript' | 'typescript' | 'python' | 'rust',
wasm: boolean,
image: {
domain: string,
repository: string,
reference: string,
digest: string,
targetDomain: string,
targetRepository: string,
targetReference: string,
progress?: {
totalBytes: number,
copiedBytes: number
},
targetError?: string
},
parameterDefinitions: ParameterDefinitions,
defaultLauncherSpecs: {
createState: LauncherSpec,
evaluate: LauncherSpec
},
maxDurationsSeconds: {
codeStartup: number,
instantiateModel: number,
createState: number,
train: number,
evaluate: number
},
filesystemSizeMebibytes: number,
ongoingTrainingSessions: string[],
trainingSessions: string[],
states: ModelState[],
activeState: string,
snapshots: {
id: string,
name: string,
createdAt: number,
filesystemSizeMebibytes: number,
parameterDefinitions: ParameterDefinitions,
defaultLauncherSpecs: {
createState: LauncherSpec,
evaluate: LauncherSpec
},
maxDurationsSeconds: {
codeStartup: number,
instantiateModel: number,
createState: number,
train: number,
evaluate: number
},
image: {
domain: string,
repository: string,
reference: string,
digest: string
},
state: {
name: string,
state: {
key: string,
byteSize: number
}[],
mountedModels: {
modelId: string,
snapshotId?: string
}[]
}
}[],
basedOnSnapshot?: {
modelId: string,
snapshotId: string,
noLongerExists: boolean
}
}
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.getModels()
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()