### Install Dependencies and Build Project Source: https://github.com/sambanova/sambanova-typescript/blob/next/CONTRIBUTING.md Run these commands to install all necessary dependencies and build the project output files. ```sh $ yarn $ yarn build ``` -------------------------------- ### Add and Execute a TypeScript Example Source: https://github.com/sambanova/sambanova-typescript/blob/next/CONTRIBUTING.md Add new example files to the 'examples/' directory and make them executable. Run examples against your API using yarn tsn. ```ts // add an example to examples/.ts #!/usr/bin/env -S npm run tsn -T … ``` ```sh $ chmod +x examples/.ts # run the example against your api $ yarn tsn -T examples/.ts ``` -------------------------------- ### Install Samba Nova Package Source: https://github.com/sambanova/sambanova-typescript/blob/next/README.md Install the Samba Nova TypeScript library using npm. ```sh npm install sambanova ``` -------------------------------- ### Install Sambanova TypeScript via Git Source: https://github.com/sambanova/sambanova-typescript/blob/next/CONTRIBUTING.md Install the Sambanova TypeScript package directly from its GitHub repository using SSH. ```sh $ npm install git+ssh://git@github.com:sambanova/sambanova-typescript.git ``` -------------------------------- ### GET /models Source: https://github.com/sambanova/sambanova-typescript/blob/next/api.md Lists all available models. This endpoint returns a collection of models that can be used. ```APIDOC ## GET /models ### Description Lists all available models. This endpoint returns a collection of models that can be used. ### Method GET ### Endpoint /models ### Response #### Success Response (200) - **ModelsResponse** - The response object containing a list of available models. ``` -------------------------------- ### GET /models/{model_id} Source: https://github.com/sambanova/sambanova-typescript/blob/next/api.md Retrieves a specific model by its ID. This endpoint provides details about a particular model. ```APIDOC ## GET /models/{model_id} ### Description Retrieves a specific model by its ID. This endpoint provides details about a particular model. ### Method GET ### Endpoint /models/{model_id} ### Parameters #### Path Parameters - **model_id** (string) - Required - The unique identifier of the model to retrieve. ### Response #### Success Response (200) - **ModelResponse** - The response object containing details of the specified model. ``` -------------------------------- ### Access Raw Response Headers and Status Source: https://github.com/sambanova/sambanova-typescript/blob/next/README.md Use the .asResponse() method to get the raw Response object. This allows access to headers and status before the body is consumed, useful for custom parsing or streaming. ```typescript const client = new SambaNova(); const response = await client.chat.completions .create({ messages: [{ content: 'create a poem using palindromes', role: 'user' }], model: 'gpt-oss-120b', }) .asResponse(); console.log(response.headers.get('X-My-Header')); console.log(response.statusText); // access the underlying Response object ``` -------------------------------- ### Set Up Mock Server for Tests Source: https://github.com/sambanova/sambanova-typescript/blob/next/CONTRIBUTING.md Before running tests, set up a mock server against the OpenAPI spec using the provided script. ```sh $ ./scripts/mock ``` -------------------------------- ### Configure Deno Proxy Source: https://github.com/sambanova/sambanova-typescript/blob/next/README.md Configure proxy behavior for Deno by creating a custom HTTP client with Deno.createHttpClient and passing it via fetchOptions. ```typescript import SambaNova from 'npm:sambanova'; const httpClient = Deno.createHttpClient({ proxy: { url: 'http://localhost:8888' } }); const client = new SambaNova({ fetchOptions: { client: httpClient, }, }); ``` -------------------------------- ### Upload Audio File using toFile helper (Buffer) Source: https://github.com/sambanova/sambanova-typescript/blob/next/README.md Transcribe an audio file using the `toFile` helper with a Buffer. ```ts await client.audio.transcriptions.create({ file: await toFile(Buffer.from('my bytes'), 'file'), model: 'Whisper-Large-v3', }); ``` -------------------------------- ### Run Project Tests Source: https://github.com/sambanova/sambanova-typescript/blob/next/CONTRIBUTING.md Execute the project's test suite using the yarn test command. ```sh $ yarn run test ``` -------------------------------- ### Upload Audio File using toFile helper (Uint8Array) Source: https://github.com/sambanova/sambanova-typescript/blob/next/README.md Transcribe an audio file using the `toFile` helper with a Uint8Array. ```ts await client.audio.transcriptions.create({ file: await toFile(new Uint8Array([0, 1, 2]), 'file'), model: 'Whisper-Large-v3', }); ``` -------------------------------- ### Create Chat Completion Source: https://github.com/sambanova/sambanova-typescript/blob/next/README.md Create a chat completion request using the Samba Nova client. Ensure the SAMBANOVA_API_KEY environment variable is set. ```js 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', }); ``` -------------------------------- ### Upload Audio File using fetch Response Source: https://github.com/sambanova/sambanova-typescript/blob/next/README.md Transcribe an audio file by passing a `fetch` `Response` object. ```ts await client.audio.transcriptions.create({ file: await fetch('https://somesite/file'), model: 'Whisper-Large-v3', }); ``` -------------------------------- ### Configure Bun Proxy Source: https://github.com/sambanova/sambanova-typescript/blob/next/README.md Configure proxy behavior for Bun by setting the proxy option directly within fetchOptions. ```typescript import SambaNova from 'sambanova'; const client = new SambaNova({ fetchOptions: { proxy: 'http://localhost:8888', }, }); ``` -------------------------------- ### Publish NPM Package Manually Source: https://github.com/sambanova/sambanova-typescript/blob/next/CONTRIBUTING.md Manually release a package by running the 'bin/publish-npm' script. Ensure the NPM_TOKEN environment variable is set. ```sh $ bin/publish-npm ``` -------------------------------- ### Provide a Custom Logger Source: https://github.com/sambanova/sambanova-typescript/blob/next/README.md Configure the SDK to use a custom logger, such as pino. The logLevel option still controls which messages are emitted. ```typescript import SambaNova from 'sambanova'; import pino from 'pino'; const logger = pino(); const client = new SambaNova({ logger: logger.child({ name: 'SambaNova' }), logLevel: 'debug', // Send all messages to pino, allowing it to filter }); ``` -------------------------------- ### Create a Response Source: https://github.com/sambanova/sambanova-typescript/blob/next/README.md Generate a response from a specified model with a given input. The output text is logged to the console. Requires API key configuration. ```js 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); ``` -------------------------------- ### Upload Audio File using File API Source: https://github.com/sambanova/sambanova-typescript/blob/next/README.md Transcribe an audio file by passing a `File` instance, compatible with the Web File API. ```ts await client.audio.transcriptions.create({ file: new File(['my bytes'], 'file'), model: 'Whisper-Large-v3', }); ``` -------------------------------- ### Link Local Sambanova TypeScript Repository with PNPM Source: https://github.com/sambanova/sambanova-typescript/blob/next/CONTRIBUTING.md Clone the repository and use 'pnpm link' to link it globally to another package. This is an alternative to yarn linking. ```sh # With pnpm $ pnpm link --global $ cd ../my-package $ pnpm link --global sambanova ``` -------------------------------- ### Pass Custom Fetch to Client Source: https://github.com/sambanova/sambanova-typescript/blob/next/README.md Alternatively, pass a custom fetch function directly to the SambaNova client constructor. ```typescript import SambaNova from 'sambanova'; import fetch from 'my-fetch'; const client = new SambaNova({ fetch }); ``` -------------------------------- ### Configure Node.js Proxy with Undici Source: https://github.com/sambanova/sambanova-typescript/blob/next/README.md Configure proxy behavior for Node.js by providing a custom ProxyAgent from 'undici' within fetchOptions. ```typescript import SambaNova from 'sambanova'; import * as undici from 'undici'; const proxyAgent = new undici.ProxyAgent('http://localhost:8888'); const client = new SambaNova({ fetchOptions: { dispatcher: proxyAgent, }, }); ``` -------------------------------- ### Upload Audio File using fs.ReadStream Source: https://github.com/sambanova/sambanova-typescript/blob/next/README.md Transcribe an audio file using `fs.createReadStream` for Node.js environments. Requires the 'fs' module. ```ts 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', }); ``` -------------------------------- ### Link Local Sambanova TypeScript Repository with Yarn Source: https://github.com/sambanova/sambanova-typescript/blob/next/CONTRIBUTING.md Clone the repository and use 'yarn link' to link it locally to another package. This is useful for development and testing changes. ```sh # Clone $ git clone https://www.github.com/sambanova/sambanova-typescript $ cd sambanova-typescript # With yarn $ yarn link $ cd ../my-package $ yarn link sambanova ``` -------------------------------- ### Set Custom Fetch Options Source: https://github.com/sambanova/sambanova-typescript/blob/next/README.md Provide a fetchOptions object to the client constructor to set custom fetch options without overriding the fetch function itself. ```typescript import SambaNova from 'sambanova'; const client = new SambaNova({ fetchOptions: { // `RequestInit` options }, }); ``` -------------------------------- ### POST /completions Source: https://github.com/sambanova/sambanova-typescript/blob/next/api.md Creates a completion request. This method is used for generating text completions based on provided prompts. ```APIDOC ## POST /completions ### Description Creates a completion request. This method is used for generating text completions based on provided prompts. ### Method POST ### Endpoint /completions ### Parameters #### Request Body - **params** (object) - Required - Parameters for the completion request. ### Response #### Success Response (200) - **CompletionCreateResponse** - The response object containing the completion details. ``` -------------------------------- ### Lint Project Code Source: https://github.com/sambanova/sambanova-typescript/blob/next/CONTRIBUTING.md Run the linting process to check for code style and potential errors using the yarn lint command. ```sh $ yarn lint ``` -------------------------------- ### POST /responses Source: https://github.com/sambanova/sambanova-typescript/blob/next/api.md Creates a response. This method is used for generating or managing responses. ```APIDOC ## POST /responses ### Description Creates a response. This method is used for generating or managing responses. ### Method POST ### Endpoint /responses ### Parameters #### Request Body - **params** (object) - Required - Parameters for the response creation. ### Response #### Success Response (200) - **ResponseCreateResponse** - The response object containing the created response. ``` -------------------------------- ### Polyfill Global Fetch Source: https://github.com/sambanova/sambanova-typescript/blob/next/README.md If you need to use a different fetch function, you can polyfill the global fetch function. ```typescript import fetch from 'my-fetch'; globalThis.fetch = fetch; ``` -------------------------------- ### POST /audio/transcriptions Source: https://github.com/sambanova/sambanova-typescript/blob/next/api.md Creates an audio transcription. This method converts spoken audio into written text. ```APIDOC ## POST /audio/transcriptions ### Description Creates an audio transcription. This method converts spoken audio into written text. ### Method POST ### Endpoint /audio/transcriptions ### Parameters #### Request Body - **params** (object) - Required - Parameters for the audio transcription request. ### Response #### Success Response (200) - **TranscriptionCreateResponse** - The response object containing the transcription. ``` -------------------------------- ### POST /audio/translations Source: https://github.com/sambanova/sambanova-typescript/blob/next/api.md Creates an audio translation. This method translates spoken audio from one language to another. ```APIDOC ## POST /audio/translations ### Description Creates an audio translation. This method translates spoken audio from one language to another. ### Method POST ### Endpoint /audio/translations ### Parameters #### Request Body - **params** (object) - Required - Parameters for the audio translation request. ### Response #### Success Response (200) - **TranslationCreateResponse** - The response object containing the translation. ``` -------------------------------- ### Configure Default Timeout Source: https://github.com/sambanova/sambanova-typescript/blob/next/README.md Set the default request timeout for all requests by initializing the SambaNova client with the timeout option. The value is in milliseconds. ```typescript // Configure the default for all requests: const client = new SambaNova({ timeout: 20 * 1000, // 20 seconds (default is 10 minutes) }); ``` -------------------------------- ### Configure Default Retries Source: https://github.com/sambanova/sambanova-typescript/blob/next/README.md Set the default number of retries for all requests by initializing the SambaNova client with the maxRetries option. Set to 0 to disable retries. ```javascript // Configure the default for all requests: const client = new SambaNova({ maxRetries: 0, // default is 2 }); ``` -------------------------------- ### Configure Logging Level Source: https://github.com/sambanova/sambanova-typescript/blob/next/README.md Set the logging level for the SambaNova client using the logLevel option during initialization. This controls the verbosity of log messages, from 'debug' to 'off'. ```typescript import SambaNova from 'sambanova'; const client = new SambaNova({ logLevel: 'debug', // Show all log messages }); ``` -------------------------------- ### POST /chat/completions Source: https://github.com/sambanova/sambanova-typescript/blob/next/api.md Creates a chat completion request. This method allows users to interact with chat models to generate text-based responses. ```APIDOC ## POST /chat/completions ### Description Creates a chat completion request. This method allows users to interact with chat models to generate text-based responses. ### Method POST ### Endpoint /chat/completions ### Parameters #### Request Body - **params** (object) - Required - Parameters for the chat completion request. ### Response #### Success Response (200) - **CompletionCreateResponse** - The response object containing the completion details. ``` -------------------------------- ### Format and Fix Lint Issues Source: https://github.com/sambanova/sambanova-typescript/blob/next/CONTRIBUTING.md Automatically format the code and fix any linting issues found in the repository using the yarn fix command. ```sh $ yarn fix ``` -------------------------------- ### Make Undocumented POST Request Source: https://github.com/sambanova/sambanova-typescript/blob/next/README.md Use client.post to make requests to undocumented endpoints. Client options like retries will be respected. ```typescript await client.post('/some/path', { body: { some_prop: 'foo' }, query: { some_query_arg: 'bar' }, }); ``` -------------------------------- ### Use Request & Response Types Source: https://github.com/sambanova/sambanova-typescript/blob/next/README.md Utilize TypeScript definitions for request parameters and response fields. This ensures type safety when interacting with the API. ```ts 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, ); ``` -------------------------------- ### Configure Per-Request Retries Source: https://github.com/sambanova/sambanova-typescript/blob/next/README.md Override the default retry behavior for a specific request by providing the maxRetries option in the second argument of the create method. ```javascript await client.chat.completions.create({ messages: [{ content: 'create a poem using palindromes', role: 'user' }], model: 'gpt-oss-120b' }, { maxRetries: 5, }); ``` -------------------------------- ### Access Raw Response and Parsed Data Source: https://github.com/sambanova/sambanova-typescript/blob/next/README.md Use the .withResponse() method to retrieve both the parsed data and the raw Response object. This method consumes the response body and returns once parsing is complete. ```typescript const { data: completion, response: raw } = await client.chat.completions .create({ messages: [{ content: 'create a poem using palindromes', role: 'user' }], model: 'gpt-oss-120b', }) .withResponse(); console.log(raw.headers.get('X-My-Header')); console.log(completion); ``` -------------------------------- ### Stream Chat Completions Source: https://github.com/sambanova/sambanova-typescript/blob/next/README.md Handle streaming responses for chat completions using Server Sent Events (SSE). The stream can be cancelled by breaking the loop or calling stream.controller.abort(). ```ts 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); } ``` -------------------------------- ### Handle API Errors Source: https://github.com/sambanova/sambanova-typescript/blob/next/README.md Catch and inspect API errors, such as BadRequestError, by checking if the error is an instance of SambaNova.APIError. This is useful for logging specific error details like status, name, and headers. ```typescript 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; } }); ``` -------------------------------- ### POST /embeddings Source: https://github.com/sambanova/sambanova-typescript/blob/next/api.md Creates embeddings for the given input text. This method is useful for natural language processing tasks that require vector representations of text. ```APIDOC ## POST /embeddings ### Description Creates embeddings for the given input text. This method is useful for natural language processing tasks that require vector representations of text. ### Method POST ### Endpoint /embeddings ### Parameters #### Request Body - **params** (object) - Required - Parameters for the embeddings request. ### Response #### Success Response (200) - **EmbeddingsResponse** - The response object containing the embeddings. ``` -------------------------------- ### Configure Per-Request Timeout Source: https://github.com/sambanova/sambanova-typescript/blob/next/README.md Override the default timeout for a specific request by providing the timeout option in the second argument of the create method. The value is in milliseconds. ```typescript await client.chat.completions.create({ messages: [{ content: 'create a poem using palindromes', role: 'user' }], model: 'gpt-oss-120b' }, { timeout: 5 * 1000, }); ``` -------------------------------- ### Use Undocumented Request Parameters Source: https://github.com/sambanova/sambanova-typescript/blob/next/README.md Add undocumented parameters to requests using '// @ts-expect-error'. Extra values sent will be included as-is. ```typescript client.chat.completions.create({ // ... // @ts-expect-error baz is not yet public baz: 'undocumented option', }); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.