This library provides convenient access to the Raccoon AI REST API from server-side TypeScript or JavaScript.
While you can provide a secretKey
keyword argument,
we recommend using environment variables for maximum security.
to add RACCOON_SECRET_KEY="My Secret Key"
to your .env
file
so that your Secret Key is not stored in source control.
We provide support for streaming responses using Server Sent Events (SSE).
If you need to cancel a stream, you can break
from the loop
or call stream.controller.abort()
.
Certain errors will be automatically retried 0 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:
Requests time out after 10 minutes by default. You can configure this with a timeout
option:
On timeout, an APIConnectionTimeoutError
is thrown.
Note that requests which time out will be retried twice by default.
By default, this library uses node-fetch
in Node, and expects a global fetch
function in other environments.
If you would prefer to use a global, web-standards-compliant fetch
function even in a Node environment,
(for example, if you are running Node with --experimental-fetch
or using NextJS which polyfills with undici
),
add the following import before your first import from "RaccoonAI"
:
To do the inverse, add import "raccoonai/shims/node"
(which does import polyfills).
This can also be useful if you are getting the wrong TypeScript types for Response
(more details).
You may also provide a custom fetch
function when instantiating the client,
which can be used to inspect or alter the Request
or Response
before/after each request:
Note that if given a DEBUG=true
environment variable, this library will log all requests and responses automatically.
This is intended for debugging purposes only and may change in the future without notice.
TypeScript >= 4.5 is supported.
The following runtimes are supported:
"node"
environment ("jsdom"
is not supported at this time).Note that React Native is not supported at this time.