├── .fernignore ├── .github └── workflows │ └── ci.yml ├── .gitignore ├── .mock ├── definition │ ├── __package__.yml │ └── api.yml ├── fern.config.json └── openapi │ └── openapi.yml ├── .npmignore ├── .prettierrc.yml ├── README.md ├── jest.config.js ├── package.json ├── reference.md ├── src ├── Client.ts ├── api │ ├── client │ │ ├── index.ts │ │ └── requests │ │ │ ├── EmbedRequest.ts │ │ │ ├── MultimodalEmbedRequest.ts │ │ │ ├── RerankRequest.ts │ │ │ └── index.ts │ ├── index.ts │ └── types │ │ ├── EmbedRequestInput.ts │ │ ├── EmbedRequestInputType.ts │ │ ├── EmbedRequestOutputDtype.ts │ │ ├── EmbedResponse.ts │ │ ├── EmbedResponseDataItem.ts │ │ ├── EmbedResponseUsage.ts │ │ ├── MultimodalEmbedRequestInputType.ts │ │ ├── MultimodalEmbedRequestInputsItem.ts │ │ ├── MultimodalEmbedRequestInputsItemContentItem.ts │ │ ├── MultimodalEmbedResponse.ts │ │ ├── MultimodalEmbedResponseDataItem.ts │ │ ├── MultimodalEmbedResponseUsage.ts │ │ ├── RerankResponse.ts │ │ ├── RerankResponseDataItem.ts │ │ ├── RerankResponseUsage.ts │ │ └── index.ts ├── core │ ├── auth │ │ ├── BasicAuth.ts │ │ ├── BearerToken.ts │ │ └── index.ts │ ├── fetcher │ │ ├── APIResponse.ts │ │ ├── Fetcher.ts │ │ ├── Supplier.ts │ │ ├── createRequestUrl.ts │ │ ├── getFetchFn.ts │ │ ├── getHeader.ts │ │ ├── getRequestBody.ts │ │ ├── getResponseBody.ts │ │ ├── index.ts │ │ ├── makeRequest.ts │ │ ├── requestWithRetries.ts │ │ ├── signals.ts │ │ └── stream-wrappers │ │ │ ├── Node18UniversalStreamWrapper.ts │ │ │ ├── NodePre18StreamWrapper.ts │ │ │ ├── UndiciStreamWrapper.ts │ │ │ └── chooseStreamWrapper.ts │ ├── index.ts │ ├── runtime │ │ ├── index.ts │ │ └── runtime.ts │ └── schemas │ │ ├── Schema.ts │ │ ├── builders │ │ ├── date │ │ │ ├── date.ts │ │ │ └── index.ts │ │ ├── enum │ │ │ ├── enum.ts │ │ │ └── index.ts │ │ ├── index.ts │ │ ├── lazy │ │ │ ├── index.ts │ │ │ ├── lazy.ts │ │ │ └── lazyObject.ts │ │ ├── list │ │ │ ├── index.ts │ │ │ └── list.ts │ │ ├── literals │ │ │ ├── booleanLiteral.ts │ │ │ ├── index.ts │ │ │ └── stringLiteral.ts │ │ ├── object-like │ │ │ ├── getObjectLikeUtils.ts │ │ │ ├── index.ts │ │ │ └── types.ts │ │ ├── object │ │ │ ├── index.ts │ │ │ ├── object.ts │ │ │ ├── objectWithoutOptionalProperties.ts │ │ │ ├── property.ts │ │ │ └── types.ts │ │ ├── primitives │ │ │ ├── any.ts │ │ │ ├── boolean.ts │ │ │ ├── index.ts │ │ │ ├── number.ts │ │ │ ├── string.ts │ │ │ └── unknown.ts │ │ ├── record │ │ │ ├── index.ts │ │ │ ├── record.ts │ │ │ └── types.ts │ │ ├── schema-utils │ │ │ ├── JsonError.ts │ │ │ ├── ParseError.ts │ │ │ ├── getSchemaUtils.ts │ │ │ ├── index.ts │ │ │ └── stringifyValidationErrors.ts │ │ ├── set │ │ │ ├── index.ts │ │ │ └── set.ts │ │ ├── undiscriminated-union │ │ │ ├── index.ts │ │ │ ├── types.ts │ │ │ └── undiscriminatedUnion.ts │ │ └── union │ │ │ ├── discriminant.ts │ │ │ ├── index.ts │ │ │ ├── types.ts │ │ │ └── union.ts │ │ ├── index.ts │ │ └── utils │ │ ├── MaybePromise.ts │ │ ├── addQuestionMarksToNullableProperties.ts │ │ ├── createIdentitySchemaCreator.ts │ │ ├── entries.ts │ │ ├── filterObject.ts │ │ ├── getErrorMessageForIncorrectType.ts │ │ ├── isPlainObject.ts │ │ ├── keys.ts │ │ ├── maybeSkipValidation.ts │ │ └── partition.ts ├── environments.ts ├── errors │ ├── VoyageAIError.ts │ ├── VoyageAITimeoutError.ts │ └── index.ts ├── index.ts └── serialization │ ├── client │ ├── index.ts │ └── requests │ │ ├── EmbedRequest.ts │ │ ├── MultimodalEmbedRequest.ts │ │ ├── RerankRequest.ts │ │ └── index.ts │ ├── index.ts │ └── types │ ├── EmbedRequestInput.ts │ ├── EmbedRequestInputType.ts │ ├── EmbedRequestOutputDtype.ts │ ├── EmbedResponse.ts │ ├── EmbedResponseDataItem.ts │ ├── EmbedResponseUsage.ts │ ├── MultimodalEmbedRequestInputType.ts │ ├── MultimodalEmbedRequestInputsItem.ts │ ├── MultimodalEmbedRequestInputsItemContentItem.ts │ ├── MultimodalEmbedResponse.ts │ ├── MultimodalEmbedResponseDataItem.ts │ ├── MultimodalEmbedResponseUsage.ts │ ├── RerankResponse.ts │ ├── RerankResponseDataItem.ts │ ├── RerankResponseUsage.ts │ └── index.ts ├── tests ├── custom.test.ts ├── custom │ ├── auth.test.ts │ └── custom.test.ts └── unit │ ├── auth │ ├── BasicAuth.test.ts │ └── BearerToken.test.ts │ ├── fetcher │ ├── Fetcher.test.ts │ ├── createRequestUrl.test.ts │ ├── getFetchFn.test.ts │ ├── getRequestBody.test.ts │ ├── getResponseBody.test.ts │ ├── makeRequest.test.ts │ ├── requestWithRetries.test.ts │ ├── signals.test.ts │ └── stream-wrappers │ │ ├── Node18UniversalStreamWrapper.test.ts │ │ ├── NodePre18StreamWrapper.test.ts │ │ ├── UndiciStreamWrapper.test.ts │ │ ├── chooseStreamWrapper.test.ts │ │ └── webpack.test.ts │ └── zurg │ ├── date │ └── date.test.ts │ ├── enum │ └── enum.test.ts │ ├── lazy │ ├── lazy.test.ts │ ├── lazyObject.test.ts │ └── recursive │ │ ├── a.ts │ │ └── b.ts │ ├── list │ └── list.test.ts │ ├── literals │ └── stringLiteral.test.ts │ ├── object-like │ └── withParsedProperties.test.ts │ ├── object │ ├── extend.test.ts │ ├── object.test.ts │ └── objectWithoutOptionalProperties.test.ts │ ├── primitives │ ├── any.test.ts │ ├── boolean.test.ts │ ├── number.test.ts │ ├── string.test.ts │ └── unknown.test.ts │ ├── record │ └── record.test.ts │ ├── schema-utils │ └── getSchemaUtils.test.ts │ ├── schema.test.ts │ ├── set │ └── set.test.ts │ ├── skipValidation.test.ts │ ├── undiscriminated-union │ └── undiscriminatedUnion.test.ts │ ├── union │ └── union.test.ts │ └── utils │ ├── itSchema.ts │ └── itValidate.ts ├── tsconfig.json └── yarn.lock /.fernignore: -------------------------------------------------------------------------------- 1 | # Specify files that shouldn't be modified by Fern 2 | tests/custom 3 | tests/integration 4 | .github/workflows/ci.yml 5 | jest.config.js 6 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: ci 2 | 3 | on: [push] 4 | 5 | jobs: 6 | compile: 7 | runs-on: ubuntu-latest 8 | 9 | steps: 10 | - name: Checkout repo 11 | uses: actions/checkout@v3 12 | 13 | - name: Set up node 14 | uses: actions/setup-node@v3 15 | 16 | - name: Compile 17 | run: yarn && yarn build 18 | 19 | unit-test: 20 | runs-on: ubuntu-latest 21 | 22 | steps: 23 | - name: Checkout repo 24 | uses: actions/checkout@v3 25 | 26 | - name: Set up node 27 | uses: actions/setup-node@v3 28 | 29 | - name: Install dependencies 30 | run: yarn install 31 | 32 | - name: Unit Test 33 | run: yarn jest tests/unit 34 | 35 | integration-test: 36 | runs-on: ubuntu-latest 37 | 38 | steps: 39 | - name: Checkout repo 40 | uses: actions/checkout@v3 41 | 42 | - name: Set up node 43 | uses: actions/setup-node@v3 44 | 45 | - name: Install dependencies 46 | run: yarn install 47 | 48 | - name: Integration Server Test 49 | env: 50 | VOYAGE_API_KEY: ${{ secrets.VOYAGE_API_KEY }} 51 | run: yarn jest tests/custom 52 | 53 | coverage: 54 | runs-on: ubuntu-latest 55 | 56 | steps: 57 | - name: Checkout repo 58 | uses: actions/checkout@v3 59 | 60 | - name: Set up node 61 | uses: actions/setup-node@v3 62 | 63 | - name: Install dependencies 64 | run: yarn install 65 | 66 | - name: Integration Server Test 67 | env: 68 | VOYAGE_API_KEY: ${{ secrets.VOYAGE_API_KEY }} 69 | run: yarn jest --coverage tests/unit tests/integration tests/custom 70 | 71 | publish: 72 | needs: [compile, unit-test, integration-test] 73 | if: github.event_name == 'push' && contains(github.ref, 'refs/tags/') && ! contains(github.ref, '0.0.0') 74 | runs-on: ubuntu-latest 75 | 76 | steps: 77 | - name: Checkout repo 78 | uses: actions/checkout@v3 79 | 80 | - name: Set up node 81 | uses: actions/setup-node@v3 82 | 83 | - name: Install dependencies 84 | run: yarn install 85 | 86 | - name: Build 87 | run: yarn build 88 | 89 | - name: Publish to npm 90 | run: | 91 | npm config set //registry.npmjs.org/:_authToken ${NPM_TOKEN} 92 | npm publish --access public 93 | env: 94 | NPM_TOKEN: ${{ secrets.NPM_TOKEN }} 95 | 96 | delete-tag-if-code-generation-only: 97 | needs: [compile, unit-test, integration-test] 98 | if: github.event_name == 'push' && contains(github.ref, 'refs/tags/') && contains(github.ref, '0.0.0') 99 | runs-on: ubuntu-latest 100 | 101 | steps: 102 | - name: Checkout repo 103 | uses: ClementTsang/delete-tag-and-release@v0.3.1 104 | with: 105 | delete_release: true 106 | tag_name: 0.0.0 # tag name to delete 107 | env: 108 | GITHUB_TOKEN: ${{ secrets.TAGGING_GITHUB_TOKEN }} 109 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .DS_Store 3 | /dist -------------------------------------------------------------------------------- /.mock/definition/api.yml: -------------------------------------------------------------------------------- 1 | name: api 2 | error-discrimination: 3 | strategy: status-code 4 | display-name: Voyage API 5 | environments: 6 | Default: https://api.voyageai.com/v1 7 | default-environment: Default 8 | auth-schemes: 9 | BearerAuthScheme: 10 | scheme: bearer 11 | token: 12 | name: apiKey 13 | env: VOYAGE_API_KEY 14 | auth: BearerAuthScheme 15 | -------------------------------------------------------------------------------- /.mock/fern.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "organization" : "voyage", 3 | "version" : "0.53.17" 4 | } -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | src 3 | tests 4 | .gitignore 5 | .github 6 | .fernignore 7 | .prettierrc.yml 8 | tsconfig.json 9 | yarn.lock -------------------------------------------------------------------------------- /.prettierrc.yml: -------------------------------------------------------------------------------- 1 | tabWidth: 4 2 | printWidth: 120 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Voyage TypeScript Library 2 | 3 | [![fern shield](https://img.shields.io/badge/%F0%9F%8C%BF-Built%20with%20Fern-brightgreen)](https://buildwithfern.com?utm_source=github&utm_medium=github&utm_campaign=readme&utm_source=https%3A%2F%2Fgithub.com%2Fvoyage-ai%2Ftypescript-sdk) 4 | [![npm shield](https://img.shields.io/npm/v/voyageai)](https://www.npmjs.com/package/voyageai) 5 | 6 | The Voyage TypeScript library provides convenient access to the Voyage API from TypeScript. 7 | 8 | ## Documentation 9 | 10 | API reference documentation is available [here](https://docs.voyageai.com/reference/embeddings-api). 11 | 12 | ## Installation 13 | 14 | ```sh 15 | npm i -s voyageai 16 | ``` 17 | 18 | ## Batch request 19 | 20 | The SDK supports batch requests. Instantiate and use the client similarly as above: 21 | 22 | ```typescript 23 | import { VoyageAIClient } from "voyageai"; 24 | 25 | const client = new VoyageAIClient({ apiKey: "YOUR_API_KEY" }); 26 | await client.embed({ 27 | input: ["input1", "input2", "input3", "input4"], 28 | model: "model", 29 | }); 30 | ``` 31 | 32 | ## Usage 33 | 34 | Instantiate and use the client with the following: 35 | 36 | ```typescript 37 | import { VoyageAIClient } from "voyageai"; 38 | 39 | const client = new VoyageAIClient({ apiKey: "YOUR_API_KEY" }); 40 | await client.embed({ 41 | input: "input", 42 | model: "model", 43 | }); 44 | ``` 45 | 46 | ## Request And Response Types 47 | 48 | The SDK exports all request and response types as TypeScript interfaces. Simply import them with the 49 | following namespace: 50 | 51 | ```typescript 52 | import { VoyageAI } from "voyageai"; 53 | 54 | const request: VoyageAI.EmbedRequest = { 55 | ... 56 | }; 57 | ``` 58 | 59 | ## Exception Handling 60 | 61 | When the API returns a non-success status code (4xx or 5xx response), a subclass of the following error 62 | will be thrown. 63 | 64 | ```typescript 65 | import { VoyageAIError } from "voyageai"; 66 | 67 | try { 68 | await client.embed(...); 69 | } catch (err) { 70 | if (err instanceof VoyageAIError) { 71 | console.log(err.statusCode); 72 | console.log(err.message); 73 | console.log(err.body); 74 | } 75 | } 76 | ``` 77 | 78 | ## Advanced 79 | 80 | ### Retries 81 | 82 | The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long 83 | as the request is deemed retriable and the number of retry attempts has not grown larger than the configured 84 | retry limit (default: 2). 85 | 86 | A request is deemed retriable when any of the following HTTP status codes is returned: 87 | 88 | - [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout) 89 | - [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests) 90 | - [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500) (Internal Server Errors) 91 | 92 | Use the `maxRetries` request option to configure this behavior. 93 | 94 | ```typescript 95 | const response = await client.embed(..., { 96 | maxRetries: 0 // override maxRetries at the request level 97 | }); 98 | ``` 99 | 100 | ### Timeouts 101 | 102 | The SDK defaults to a 60 second timeout. Use the `timeoutInSeconds` option to configure this behavior. 103 | 104 | ```typescript 105 | const response = await client.embed(..., { 106 | timeoutInSeconds: 30 // override timeout to 30s 107 | }); 108 | ``` 109 | 110 | ### Aborting Requests 111 | 112 | The SDK allows users to abort requests at any point by passing in an abort signal. 113 | 114 | ```typescript 115 | const controller = new AbortController(); 116 | const response = await client.embed(..., { 117 | abortSignal: controller.signal 118 | }); 119 | controller.abort(); // aborts the request 120 | ``` 121 | 122 | ### Runtime Compatibility 123 | 124 | The SDK defaults to `node-fetch` but will use the global fetch client if present. The SDK works in the following 125 | runtimes: 126 | 127 | - Node.js 18+ 128 | - Vercel 129 | - Cloudflare Workers 130 | - Deno v1.25+ 131 | - Bun 1.0+ 132 | - React Native 133 | 134 | ### Customizing Fetch Client 135 | 136 | The SDK provides a way for your to customize the underlying HTTP client / Fetch function. If you're running in an 137 | unsupported environment, this provides a way for you to break glass and ensure the SDK works. 138 | 139 | ```typescript 140 | import { VoyageAIClient } from "voyageai"; 141 | 142 | const client = new VoyageAIClient({ 143 | ... 144 | fetcher: // provide your implementation here 145 | }); 146 | ``` 147 | 148 | ## Contributing 149 | 150 | While we value open-source contributions to this SDK, this library is generated programmatically. 151 | Additions made directly to this library would have to be moved over to our generation code, 152 | otherwise they would be overwritten upon the next generated release. Feel free to open a PR as 153 | a proof of concept, but know that we will not be able to merge it as-is. We suggest opening 154 | an issue first to discuss with us! 155 | 156 | On the other hand, contributions to the README are always very welcome! 157 | -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('jest').Config} */ 2 | module.exports = { 3 | preset: "ts-jest", 4 | testEnvironment: "node", 5 | coverageThreshold: { 6 | "global": { 7 | "branches": 70, 8 | "functions": 80, 9 | "lines": 85, 10 | "statements": 85, 11 | } 12 | } 13 | }; 14 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "voyageai", 3 | "version": "0.0.4", 4 | "private": false, 5 | "repository": "https://github.com/voyage-ai/typescript-sdk", 6 | "main": "./index.js", 7 | "types": "./index.d.ts", 8 | "scripts": { 9 | "format": "prettier . --write --ignore-unknown", 10 | "build": "tsc", 11 | "prepack": "cp -rv dist/. .", 12 | "test": "jest" 13 | }, 14 | "dependencies": { 15 | "url-join": "4.0.1", 16 | "form-data": "^4.0.0", 17 | "formdata-node": "^6.0.3", 18 | "node-fetch": "2.7.0", 19 | "qs": "6.11.2", 20 | "readable-stream": "^4.5.2", 21 | "js-base64": "3.7.2" 22 | }, 23 | "devDependencies": { 24 | "@types/url-join": "4.0.1", 25 | "@types/qs": "6.9.8", 26 | "@types/node-fetch": "2.6.9", 27 | "@types/readable-stream": "^4.0.15", 28 | "fetch-mock-jest": "^1.5.1", 29 | "webpack": "^5.94.0", 30 | "ts-loader": "^9.3.1", 31 | "jest": "29.7.0", 32 | "@types/jest": "29.5.5", 33 | "ts-jest": "29.1.1", 34 | "jest-environment-jsdom": "29.7.0", 35 | "@types/node": "17.0.33", 36 | "prettier": "2.7.1", 37 | "typescript": "4.6.4" 38 | }, 39 | "browser": { 40 | "fs": false, 41 | "os": false, 42 | "path": false 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /reference.md: -------------------------------------------------------------------------------- 1 | # Reference 2 | 3 |
client.multimodalEmbed({ ...params }) -> VoyageAI.MultimodalEmbedResponse 4 |
5 |
6 | 7 | #### 📝 Description 8 | 9 |
10 |
11 | 12 |
13 |
14 | 15 | The Voyage multimodal embedding endpoint returns vector representations for a given list of multimodal inputs consisting of text, images, or an interleaving of both modalities. 16 | 17 |
18 |
19 |
20 |
21 | 22 | #### 🔌 Usage 23 | 24 |
25 |
26 | 27 |
28 |
29 | 30 | ```typescript 31 | await client.multimodalEmbed({ 32 | inputs: [{}], 33 | model: "model", 34 | }); 35 | ``` 36 | 37 |
38 |
39 |
40 |
41 | 42 | #### ⚙️ Parameters 43 | 44 |
45 |
46 | 47 |
48 |
49 | 50 | **request:** `VoyageAI.MultimodalEmbedRequest` 51 | 52 |
53 |
54 | 55 |
56 |
57 | 58 | **requestOptions:** `VoyageAIClient.RequestOptions` 59 | 60 |
61 |
62 |
63 |
64 | 65 |
66 |
67 |
68 | 69 | ## 70 | -------------------------------------------------------------------------------- /src/api/client/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./requests"; 2 | -------------------------------------------------------------------------------- /src/api/client/requests/EmbedRequest.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This file was auto-generated by Fern from our API Definition. 3 | */ 4 | 5 | import * as VoyageAI from "../../index"; 6 | 7 | /** 8 | * @example 9 | * { 10 | * input: "input", 11 | * model: "model" 12 | * } 13 | */ 14 | export interface EmbedRequest { 15 | /** 16 | * A single text string, or a list of texts as a list of strings. Currently, we have two constraints on the list: