Assembly AI Node Library
The Assembly AI Node.js library provides access to the Assembly AI API from JavaScript/TypeScript.
Documentation
API reference documentation is available here.
Installation
npm install --save @fern-api/assemblyai
# or
yarn add @fern-api/assemblyai
HTTP Client Usage
The SDK exports a vanilla HTTP client, AssemblyAIClient
. You can
use this to call into each of our API endpoints and get typed
responses back.
import { AssemblyAIClient } from "@fern-api/assemblyai";
const aai = new AssemblyAIClient({
apiKey: "YOUR_API_KEY",
});
const transcript = await aai.transcript.get("transcript-id");
console.log("Received response!", transcript);
Handling Errors
When the API returns a non-success status code (4xx or 5xx response),
a subclass of AssemblyAIError
will be thrown:
import { AssemblyAIClient, AssemblyAIError } from "@fern-api/assemblyai";
try {
const transcript = await aai.transcript.get("transcript-id");
} catch (err) {
if (err instanceof AssemblyAIError) {
console.log(err.statusCode);
console.log(err.message);
console.log(err.body);
}
}
Request Options
The HTTP Client accepts a RequestOptions
class where you can specify
a customized timeout.
const transcript = await aai.transcript.get("transcript-id", {
timeoutInSeconds: 60
});
Using the Transcriber class
Additionally, the SDK also exports a Transcriber class that has
utilities on top of the HTTP client, such as automatic polling.
import { Transcriber } from "@fern-api/assemblyai";
const transcriber = new Transcriber({
apiKey: "YOUR_API_KEY",
});
const transcript = await transcriber.transcribe({
data: "https://example.org/audio.mp3",
poll: true,
});
console.log(transcript.text);
Beta status
This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning the package version to a specific version in your package.json file. This way, you can install the same version each time without breaking changes unless you are intentionally looking for the latest version.
Contributing
While we value open-source contributions to this SDK, this library is generated programmatically. Additions made directly to this library would have to be moved over to our generation code, otherwise they would be overwritten upon the next generated release. Feel free to open a PR as a proof of concept, but know that we will not be able to merge it as-is. We suggest opening an issue first to discuss with us!
On the other hand, contributions to the README are always very welcome!