Learn how to use supermemory with Typescript
File
(or an object with the same structure)fetch
Response
(or an object with the same structure)fs.ReadStream
toFile
helperAPIError
will be thrown:
Status Code | Error Type |
---|---|
400 | BadRequestError |
401 | AuthenticationError |
403 | PermissionDeniedError |
404 | NotFoundError |
422 | UnprocessableEntityError |
429 | RateLimitError |
>=500 | InternalServerError |
N/A | APIConnectionError |
maxRetries
option to configure or disable this:
timeout
option:
APIConnectionTimeoutError
is thrown.
Note that requests which time out will be retried twice by default.
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 streaming logic.
You can also use the .withResponse()
method to get the raw Response
along with the parsed data.
Unlike .asResponse()
this method consumes the body, returning once it is parsed.
SUPERMEMORY_LOG
environment variablelogLevel
client option (overrides the environment variable if set)'debug'
- Show debug messages, info, warnings, and errors'info'
- Show info messages, warnings, and errors'warn'
- Show warnings and errors (default)'error'
- Show only errors'off'
- Disable all logging'debug'
level, all HTTP requests and responses are logged, including headers and bodies.
Some authentication-related headers are redacted, but sensitive data in request and response bodies
may still be visible.
globalThis.console
. You can also provide a custom logger.
Most logging libraries are supported, including pino, winston, bunyan, consola, signale, and @std/log. If your logger doesn’t work, please open an issue.
When providing a custom logger, the logLevel
option still controls which messages are emitted, messages
below the configured level will not be sent to your logger.
client.get
, client.post
, and other HTTP verbs.
Options on the client, such as retries, will be respected when making these requests.
// @ts-expect-error
on the undocumented
parameter. This library doesn’t validate at runtime that the request matches the type, so any extra values you
send will be sent as-is.
GET
verb, any extra params will be in the query, all other requests will send the
extra param in the body.
If you want to explicitly send an extra argument, you can do so with the query
, body
, and headers
request
options.
// @ts-expect-error
on
the response object, or cast the response object to the requisite type. Like the request params, we do not
validate or strip extra properties from the response from the API.
fetch
function is defined.
If you want to use a different fetch
function, you can either polyfill the global:
fetch
options without overriding the fetch
function, you can provide a fetchOptions
object when instantiating the client or making a request. (Request-specific options override client options.)
fetchOptions
that add runtime-specific proxy options to requests:
"node"
environment ("jsdom"
is not supported at this time).