TypeScript SDK

The Arche TypeScript SDK is a thin, typed client for the same public routes documented in the API reference. It runs on Node.js 18 or later and any runtime with a standard fetch, and it is licensed under Apache 2.0.

Install

npm install arche-sdk

Create a client

import { Arche } from 'arche-sdk'

const arche = new Arche({ apiKey: process.env.ARCHE_API_KEY })
  • Name
    apiKey
    Type
    string | undefined
    Description

    Sent as the X-Api-Key header. When omitted, the client reads the ARCHE_API_KEY environment variable. Create a key in the developer portal.

  • Name
    baseUrl
    Type
    string
    Description

    Defaults to https://api.arche.fi.

  • Name
    fetch
    Type
    typeof fetch
    Description

    Supply your own fetch when you need custom retries, proxies, or timeouts. Defaults to the global fetch.

Methods and types

Every public route is a method named for its OpenAPI operationId, with typed path, query and body arguments and a typed response envelope. Every schema is exported as a type under Schemas. The methods and types are generated from the published OpenAPI document, and a new version is released whenever that document changes.

The quickstart flow in TypeScript

This mirrors the Quickstart step for step.

import { Arche, snapshotHashOf } from 'arche-sdk'

const arche = new Arche()

// Step 2 - resolve a ticker to a canonical CIK
const resolved = await arche.resolveCompany({ ticker: 'MSFT' })

// Step 3 - list statements for that issuer
const statements = await arche.listStatements(resolved.data.cik, {
  statement_type: 'INCOME_STATEMENT',
  page: 1,
  page_size: 10,
})
console.log(statements.total, 'statements')

// Step 4 - ask what was knowable on a historical date
const pointInTime = await arche.getAsOfFinancials('0000320193', '2024-03-31')
console.log(snapshotHashOf(pointInTime))

Derived metrics come from the same client:

const series = await arche.getDerivedMetricsTimeSeries({
  ciks: ['0000320193'],
  statement_type: 'INCOME_STATEMENT',
  metrics: ['GROSS_MARGIN'],
  frequency: 'annual',
})
console.log(series.data.points.length)

Replay tokens and snapshot hashes

A point-in-time query returns a replay token that anyone can re-check against the same data. replayTokenOf and snapshotHashOf find them in any response, verifyReplayToken re-runs a token, and verifyUrl gives a public page that checks it without a key.

import { Arche, replayTokenOf, verifyUrl } from 'arche-sdk'

const arche = new Arche()

const { data } = await arche.resolveCompanyAsOf({ ticker: 'AAPL' })
const executed = await arche.executeQuery({
  query_type: 'financials_as_of_page',
  parameters: { cik: data.identity.cik, limit: 1, latest_only: true },
  as_of_date: '2024-11-02',
})
const token = replayTokenOf(executed)!
const verification = await arche.verifyReplayToken(token)
console.log(verifyUrl(token))

See Verifiable agent answers for what a verification checks.

Error handling

A failed request throws ArcheApiError, carrying the error envelope's status, code, traceId and details.

import { Arche, ArcheApiError } from 'arche-sdk'

const arche = new Arche()

try {
  await arche.resolveCompany({ ticker: 'MSFT' })
} catch (error) {
  if (error instanceof ArcheApiError) {
    console.log(error.status, error.code, error.traceId)
  }
  throw error
}

Log the traceId with any failure you report; it identifies the request on Arche's side.

Was this page helpful?