This client SDK runs on ES6-compatible Javascript runtimes with async/await supports such as NodeJS 7+ and modern web browsers released since 2017.
$ npm install backend.ai-clientTypeScript:
import * as ai from 'backend.ai-client';
let config = ai.backend.ClientConfig.createFromEnv();
let client = new ai.backend.Client(config);CommonJS-style:
const ai = require('backend.ai-client');
let config = ai.backend.ClientConfig.createFromEnv();
let client = new ai.backend.Client(config);When creating ClientConfig object, you can manually pass accessKey,
secretKey, and optional endpoint arguments.
The environment variables are:
BACKEND_ACCESS_KEYBACKEND_SECRET_KEYBACKEND_ENDPOINT(optional, defaults tohttps://api.backend.ai)
All API functions return a promise that resolves into a parsed object
when success according to server-provided Content-Type and rejects with an
object with type and message attributes if failed.
client.createIfNotExists('python:latest', 'my-session-id')
.then(response => {
console.log(`my session is created: ${response.kernelId}`);
}).catch(err => {
switch (err.type) {
case ai.backend.Client.ERR_SERVER:
console.log(`session creation failed: ${err.message}`);
break;
default:
console.log(`request/response failed: ${err.message}`);
}
});The result objects returned with success has different formats API by API. Please check out our official documentation.
err.type is one of the following values:
ai.backend.Client.ERR_SERVER: The server responded with failure. In this case,err.messageincludes HTTP status and additional error information returned by the API server.ai.backend.Client.ERR_RESPONSE: An error occurred while reading the response.err.messageincludes an exception value passed from your Javascript runtime.ai.backend.Client.ERR_REQUEST: An error occurred while sending the request.err.messageincludes an exception value passed from your Javascript runtime.