Gathering detailed insights and metrics for @inkeep/ai-api
Gathering detailed insights and metrics for @inkeep/ai-api
Gathering detailed insights and metrics for @inkeep/ai-api
Gathering detailed insights and metrics for @inkeep/ai-api
npm install @inkeep/ai-api
Typescript
Module System
Node Version
NPM Version
typescript - v0.8.0 - 2024-09-24 18:38:30
Updated on Sep 24, 2024
typescript - v0.7.2 - 2024-04-25 19:07:34
Updated on Apr 25, 2024
typescript - v0.6.2 - 2024-04-13 00:06:07
Updated on Apr 13, 2024
typescript - v0.6.1 - 2024-04-02 00:06:05
Updated on Apr 02, 2024
typescript - v0.6.0 - 2024-03-27 00:06:17
Updated on Mar 27, 2024
typescript - v0.5.3 - 2024-03-20 00:05:44
Updated on Mar 20, 2024
TypeScript (98.87%)
Makefile (0.64%)
JavaScript (0.49%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
11 Stars
108 Commits
2 Forks
2 Watchers
11 Branches
4 Contributors
Updated on Jun 09, 2025
Latest Version
0.8.0
Package Id
@inkeep/ai-api@0.8.0
Unpacked Size
556.98 kB
Size
102.25 kB
File Count
310
NPM Version
8.19.4
Node Version
16.20.2
Published on
Sep 24, 2024
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
1
Inkeep Search and Chat API: Leverage the Inkeep APIs to create your own AI-powered search and chat experiences built on top of your own content.
The SDK can be installed with either npm, pnpm, bun or yarn package managers.
1npm add @inkeep/ai-api
1pnpm add @inkeep/ai-api
1bun add @inkeep/ai-api
1yarn add @inkeep/ai-api zod 2 3# Note that Yarn does not install peer dependencies automatically. You will need 4# to install zod as shown above.
For supported JavaScript runtimes, please consult RUNTIMES.md.
1import { InkeepAI } from "@inkeep/ai-api"; 2 3const inkeepAI = new InkeepAI({ 4 apiKey: "<YOUR_BEARER_TOKEN_HERE>", 5}); 6 7async function run() { 8 const result = await inkeepAI.chatSession.create({ 9 integrationId: "<value>", 10 chatSession: { 11 messages: [ 12 { 13 content: "<value>", 14 }, 15 ], 16 }, 17 }); 18 19 if (result.chatResultStream == null) { 20 throw new Error("failed to create stream: received null value"); 21 } 22 23 for await (const event of result.chatResultStream) { 24 // Handle the event 25 console.log(event); 26 } 27} 28 29run(); 30
All the methods listed above are available as standalone functions. These functions are ideal for use in applications running in the browser, serverless runtimes or other environments where application bundle size is a primary concern. When using a bundler to build your application, all unused functionality will be either excluded from the final bundle or tree-shaken away.
To read more about standalone functions, check FUNCTIONS.md.
Server-sent events are used to stream content from certain
operations. These operations will expose the stream as an async iterable that
can be consumed using a for await...of
loop. The loop will
terminate when the server no longer has any events to send and closes the
underlying connection.
1import { InkeepAI } from "@inkeep/ai-api"; 2 3const inkeepAI = new InkeepAI({ 4 apiKey: "<YOUR_BEARER_TOKEN_HERE>", 5}); 6 7async function run() { 8 const result = await inkeepAI.chatSession.create({ 9 integrationId: "<value>", 10 chatSession: { 11 messages: [ 12 { 13 content: "<value>", 14 }, 15 ], 16 }, 17 }); 18 19 if (result.chatResultStream == null) { 20 throw new Error("failed to create stream: received null value"); 21 } 22 23 for await (const event of result.chatResultStream) { 24 // Handle the event 25 console.log(event); 26 } 27} 28 29run(); 30
Some of the endpoints in this SDK support retries. If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API. However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.
To change the default retry strategy for a single API call, simply provide a retryConfig object to the call:
1import { InkeepAI } from "@inkeep/ai-api"; 2 3const inkeepAI = new InkeepAI({ 4 apiKey: "<YOUR_BEARER_TOKEN_HERE>", 5}); 6 7async function run() { 8 const result = await inkeepAI.chatSession.create({ 9 integrationId: "<value>", 10 chatSession: { 11 messages: [ 12 { 13 content: "<value>", 14 }, 15 ], 16 }, 17 }, { 18 retries: { 19 strategy: "backoff", 20 backoff: { 21 initialInterval: 1, 22 maxInterval: 50, 23 exponent: 1.1, 24 maxElapsedTime: 100, 25 }, 26 retryConnectionErrors: false, 27 }, 28 }); 29 30 if (result.chatResultStream == null) { 31 throw new Error("failed to create stream: received null value"); 32 } 33 34 for await (const event of result.chatResultStream) { 35 // Handle the event 36 console.log(event); 37 } 38} 39 40run(); 41
If you'd like to override the default retry strategy for all operations that support retries, you can provide a retryConfig at SDK initialization:
1import { InkeepAI } from "@inkeep/ai-api"; 2 3const inkeepAI = new InkeepAI({ 4 retryConfig: { 5 strategy: "backoff", 6 backoff: { 7 initialInterval: 1, 8 maxInterval: 50, 9 exponent: 1.1, 10 maxElapsedTime: 100, 11 }, 12 retryConnectionErrors: false, 13 }, 14 apiKey: "<YOUR_BEARER_TOKEN_HERE>", 15}); 16 17async function run() { 18 const result = await inkeepAI.chatSession.create({ 19 integrationId: "<value>", 20 chatSession: { 21 messages: [ 22 { 23 content: "<value>", 24 }, 25 ], 26 }, 27 }); 28 29 if (result.chatResultStream == null) { 30 throw new Error("failed to create stream: received null value"); 31 } 32 33 for await (const event of result.chatResultStream) { 34 // Handle the event 35 console.log(event); 36 } 37} 38 39run(); 40
All SDK methods return a response object or throw an error. If Error objects are specified in your OpenAPI Spec, the SDK will throw the appropriate Error type.
Error Object | Status Code | Content Type |
---|---|---|
errors.HTTPValidationError | 422 | application/json |
errors.SDKError | 4xx-5xx | / |
Validation errors can also occur when either method arguments or data returned from the server do not match the expected format. The SDKValidationError
that is thrown as a result will capture the raw value that failed validation in an attribute called rawValue
. Additionally, a pretty()
method is available on this error that can be used to log a nicely formatted string since validation errors can list many issues and the plain error string may be difficult read when debugging.
1import { InkeepAI } from "@inkeep/ai-api"; 2import { 3 HTTPValidationError, 4 SDKValidationError, 5} from "@inkeep/ai-api/models/errors"; 6 7const inkeepAI = new InkeepAI({ 8 apiKey: "<YOUR_BEARER_TOKEN_HERE>", 9}); 10 11async function run() { 12 let result; 13 try { 14 result = await inkeepAI.chatSession.create({ 15 integrationId: "<value>", 16 chatSession: { 17 messages: [ 18 { 19 content: "<value>", 20 }, 21 ], 22 }, 23 }); 24 25 if (result.chatResultStream == null) { 26 throw new Error("failed to create stream: received null value"); 27 } 28 29 for await (const event of result.chatResultStream) { 30 // Handle the event 31 console.log(event); 32 } 33 } catch (err) { 34 switch (true) { 35 case (err instanceof SDKValidationError): { 36 // Validation errors can be pretty-printed 37 console.error(err.pretty()); 38 // Raw value may also be inspected 39 console.error(err.rawValue); 40 return; 41 } 42 case (err instanceof HTTPValidationError): { 43 // Handle err.data$: HTTPValidationErrorData 44 console.error(err); 45 return; 46 } 47 default: { 48 throw err; 49 } 50 } 51 } 52} 53 54run(); 55
You can override the default server globally by passing a server index to the serverIdx
optional parameter when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the indexes associated with the available servers:
# | Server | Variables |
---|---|---|
0 | https://api.inkeep.com | None |
1import { InkeepAI } from "@inkeep/ai-api"; 2 3const inkeepAI = new InkeepAI({ 4 serverIdx: 0, 5 apiKey: "<YOUR_BEARER_TOKEN_HERE>", 6}); 7 8async function run() { 9 const result = await inkeepAI.chatSession.create({ 10 integrationId: "<value>", 11 chatSession: { 12 messages: [ 13 { 14 content: "<value>", 15 }, 16 ], 17 }, 18 }); 19 20 if (result.chatResultStream == null) { 21 throw new Error("failed to create stream: received null value"); 22 } 23 24 for await (const event of result.chatResultStream) { 25 // Handle the event 26 console.log(event); 27 } 28} 29 30run(); 31
The default server can also be overridden globally by passing a URL to the serverURL
optional parameter when initializing the SDK client instance. For example:
1import { InkeepAI } from "@inkeep/ai-api"; 2 3const inkeepAI = new InkeepAI({ 4 serverURL: "https://api.inkeep.com", 5 apiKey: "<YOUR_BEARER_TOKEN_HERE>", 6}); 7 8async function run() { 9 const result = await inkeepAI.chatSession.create({ 10 integrationId: "<value>", 11 chatSession: { 12 messages: [ 13 { 14 content: "<value>", 15 }, 16 ], 17 }, 18 }); 19 20 if (result.chatResultStream == null) { 21 throw new Error("failed to create stream: received null value"); 22 } 23 24 for await (const event of result.chatResultStream) { 25 // Handle the event 26 console.log(event); 27 } 28} 29 30run(); 31
The TypeScript SDK makes API calls using an HTTPClient
that wraps the native
Fetch API. This
client is a thin wrapper around fetch
and provides the ability to attach hooks
around the request lifecycle that can be used to modify the request or handle
errors and response.
The HTTPClient
constructor takes an optional fetcher
argument that can be
used to integrate a third-party HTTP client or when writing tests to mock out
the HTTP client and feed in fixtures.
The following example shows how to use the "beforeRequest"
hook to to add a
custom header and a timeout to requests and how to use the "requestError"
hook
to log errors:
1import { InkeepAI } from "@inkeep/ai-api"; 2import { HTTPClient } from "@inkeep/ai-api/lib/http"; 3 4const httpClient = new HTTPClient({ 5 // fetcher takes a function that has the same signature as native `fetch`. 6 fetcher: (request) => { 7 return fetch(request); 8 } 9}); 10 11httpClient.addHook("beforeRequest", (request) => { 12 const nextRequest = new Request(request, { 13 signal: request.signal || AbortSignal.timeout(5000) 14 }); 15 16 nextRequest.headers.set("x-custom-header", "custom value"); 17 18 return nextRequest; 19}); 20 21httpClient.addHook("requestError", (error, request) => { 22 console.group("Request Error"); 23 console.log("Reason:", `${error}`); 24 console.log("Endpoint:", `${request.method} ${request.url}`); 25 console.groupEnd(); 26}); 27 28const sdk = new InkeepAI({ httpClient });
This SDK supports the following security scheme globally:
Name | Type | Scheme |
---|---|---|
apiKey | http | HTTP Bearer |
To authenticate with the API the apiKey
parameter must be set when initializing the SDK client instance. For example:
1import { InkeepAI } from "@inkeep/ai-api"; 2 3const inkeepAI = new InkeepAI({ 4 apiKey: "<YOUR_BEARER_TOKEN_HERE>", 5}); 6 7async function run() { 8 const result = await inkeepAI.chatSession.create({ 9 integrationId: "<value>", 10 chatSession: { 11 messages: [ 12 { 13 content: "<value>", 14 }, 15 ], 16 }, 17 }); 18 19 if (result.chatResultStream == null) { 20 throw new Error("failed to create stream: received null value"); 21 } 22 23 for await (const event of result.chatResultStream) { 24 // Handle the event 25 console.log(event); 26 } 27} 28 29run(); 30
You can setup your SDK to emit debug logs for SDK requests and responses.
You can pass a logger that matches console
's interface as an SDK option.
[!WARNING] Beware that debug logging will reveal secrets, like API tokens in headers, in log messages printed to a console or files. It's recommended to use this feature only during local development and not in production.
1import { InkeepAI } from "@inkeep/ai-api"; 2 3const sdk = new InkeepAI({ debugLogger: console });
This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage to a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionally looking for the latest version.
While we value open-source contributions to this SDK, this library is generated programmatically. Feel free to open a PR or a Github issue as a proof of concept and we'll do our best to include it in a future release!
No vulnerabilities found.
No security vulnerabilities found.