RepoSambaNova SystemsSambaNova Systemspublished Aug 20, 2025seen 5d

sambanova/sambanova-typescript

TypeScript

Open original ↗

Captured source

source ↗
published Aug 20, 2025seen 5dcaptured 8hhttp 200method plain

sambanova/sambanova-typescript

Language: TypeScript

License: Apache-2.0

Stars: 1

Forks: 1

Open issues: 0

Created: 2025-08-20T22:17:13Z

Pushed: 2026-05-26T21:58:28Z

Default branch: next

Fork: no

Archived: no

README:

Samba Nova TypeScript API Library

This library provides convenient access to the Samba Nova REST API from server-side TypeScript or JavaScript.

The REST API documentation can be found on docs.sambanova.ai. The full API of this library can be found in [api.md](api.md).

It is generated with Stainless.

Installation

npm install sambanova

Usage

The full API of this library can be found in [api.md](api.md).

import SambaNova from 'sambanova';

const client = new SambaNova({
apiKey: process.env['SAMBANOVA_API_KEY'], // This is the default and can be omitted
});

const completion = await client.chat.completions.create({
messages: [{ content: 'create a poem using palindromes', role: 'user' }],
model: 'gpt-oss-120b',
});

Responses API

import SambaNova from 'sambanova';

const client = new SambaNova({
apiKey: process.env['SAMBANOVA_API_KEY'],
});

const response = await client.responses.create({
model: 'gpt-oss-120b',
input: 'Explain disestablishmentarianism to a smart five year old.',
});
console.log(response.output_text);

Streaming responses

We provide support for streaming responses using Server Sent Events (SSE).

import SambaNova from 'sambanova';

const client = new SambaNova();

const stream = await client.chat.completions.create({
messages: [{ content: 'create a poem using palindromes', role: 'user' }],
model: 'gpt-oss-120b',
stream: true,
});
for await (const chatCompletionStreamResponse of stream) {
console.log(chatCompletionStreamResponse);
}

If you need to cancel a stream, you can break from the loop or call stream.controller.abort().

Request & Response types

This library includes TypeScript definitions for all request params and response fields. You may import and use them like so:

import SambaNova from 'sambanova';

const client = new SambaNova({
apiKey: process.env['SAMBANOVA_API_KEY'], // This is the default and can be omitted
});

const params: SambaNova.Chat.CompletionCreateParams = {
messages: [{ content: 'create a poem using palindromes', role: 'user' }],
model: 'gpt-oss-120b',
};
const completion: SambaNova.Chat.CompletionCreateResponse = await client.chat.completions.create(
params,
);

Documentation for each method, request param, and response field are available in docstrings and will appear on hover in most modern editors.

File uploads

Request parameters that correspond to file uploads can be passed in many different forms:

  • File (or an object with the same structure)
  • a fetch Response (or an object with the same structure)
  • an fs.ReadStream
  • the return value of our toFile helper
import fs from 'fs';
import SambaNova, { toFile } from 'sambanova';

const client = new SambaNova();

// If you have access to Node `fs` we recommend using `fs.createReadStream()`:
await client.audio.transcriptions.create({
file: fs.createReadStream('/path/to/file'),
model: 'Whisper-Large-v3',
});

// Or if you have the web `File` API you can pass a `File` instance:
await client.audio.transcriptions.create({
file: new File(['my bytes'], 'file'),
model: 'Whisper-Large-v3',
});

// You can also pass a `fetch` `Response`:
await client.audio.transcriptions.create({
file: await fetch('https://somesite/file'),
model: 'Whisper-Large-v3',
});

// Finally, if none of the above are convenient, you can use our `toFile` helper:
await client.audio.transcriptions.create({
file: await toFile(Buffer.from('my bytes'), 'file'),
model: 'Whisper-Large-v3',
});
await client.audio.transcriptions.create({
file: await toFile(new Uint8Array([0, 1, 2]), 'file'),
model: 'Whisper-Large-v3',
});

Handling errors

When the library is unable to connect to the API, or if the API returns a non-success status code (i.e., 4xx or 5xx response), a subclass of APIError will be thrown:

const completion = await client.chat.completions
.create({
messages: [{ content: 'create a poem using palindromes', role: 'user' }],
model: 'gpt-oss-120b',
})
.catch(async (err) => {
if (err instanceof SambaNova.APIError) {
console.log(err.status); // 400
console.log(err.name); // BadRequestError
console.log(err.headers); // {server: 'nginx', ...}
} else {
throw err;
}
});

Error codes are as follows:

| Status Code | Error Type | | ----------- | -------------------------- | | 400 | BadRequestError | | 401 | AuthenticationError | | 403 | PermissionDeniedError | | 404 | NotFoundError | | 422 | UnprocessableEntityError | | 429 | RateLimitError | | >=500 | InternalServerError | | N/A | APIConnectionError |

Retries

Certain errors will be automatically retried 2 times by default, with a short exponential backoff. Connection errors (for example, due to a network connectivity problem), 408 Request Timeout, 409 Conflict, 429 Rate Limit, and >=500 Internal errors will all be retried by default.

You can use the maxRetries option to configure or disable this:

// Configure the default for all requests:
const client = new SambaNova({
maxRetries: 0, // default is 2
});

// Or, configure per-request:
await client.chat.completions.create({ messages: [{ content: 'create a poem using palindromes', role: 'user' }], model: 'gpt-oss-120b' }, {
maxRetries: 5,
});

Timeouts

Requests time out after 10 minutes by default. You can configure this with a timeout option:

// Configure the default for all requests:
const client = new SambaNova({
timeout: 20 * 1000, // 20 seconds (default is 10 minutes)
});

// Override per-request:
await client.chat.completions.create({ messages: [{ content: 'create a poem using palindromes', role: 'user' }], model: 'gpt-oss-120b' }, {
timeout: 5 * 1000,
});

On timeout, an APIConnectionTimeoutError is thrown.

Note that requests which time out will be [retried twice by default](#retries).

Advanced Usage

Accessing raw Response data (e.g., headers)

The "raw" Response returned by fetch() can be accessed through the .asResponse() method on the APIPromise type that all methods return. This method returns as soon as the headers for a successful response are received and does not consume the response body, so you are free to write custom parsing or…

Excerpt shown — open the source for the full document.

Notability

notability 2.0/10

New repo with negligible traction