Using the JavaScript SDK
The Metorial JavaScript SDK allows you to interact with the Metorial API using TypeScript or JavaScript. The SDK is available for use in the browser, Node.js, and Deno environments.
What you will learn
How to install the Metorial JavaScript SDK
How to use the SDK in the browser, Node.js, and Deno environments
How to make requests to the Metorial API using the SDK
Before you begin
References
Install the SDK
To install the Metorial JavaScript SDK, use npm or yarn:
npm install @metorial/sdk
yarn add @metorial/sdk
Using the SDK
To use the SDK, import the Metorial
class and create an instance with your API key:
1import Metorial from '@metorial/client';23const metorial = new Metorial('metorial_pk_abc123');
You can now use the metorial
instance to make requests to the Metorial API.
Making Requests
To make a request, use the request
method on the metorial
instance:
const threads = await metorial.thread.get('thread_0m4irw3bu74KzqZr3EVmzz');
The request
method returns a Promise that resolves with the response data.
Using TypeScript
The SDK is written in TypeScript and includes type definitions for all API resources. You can use TypeScript to benefit from type checking and IntelliSense support:
1import Metorial, { MetorialThread } from '@metorial/client';23const metorial = new Metorial('metorial_pk_abc123');4const thread: MetorialThread = await metorial.thread.get('thread_0m4irw3bu74KzqZr3EVmzz');