Get in touch

SDK or REST API

We offer multiple SDKs to make the development experience even easier.

Currently, we have an SDK for the following languages:

  • Python
  • Typescript

If you are using a language that is not supported yet, you can still leverage the REST API.

Choosing between an SDK or calling the API directly

You have to ask yourself what you prefer between the two options:

Going with the SDK:

  • (+) You get tested code ready to use
  • (+) You get type definition
  • (+) You get basic functionalities enabled (retry, error handling)
  • (-) You have slightly more dependencies (although we make sure it's the bare minimum)
  • (-) You will be forced to follow our code style based on TS, which can clash with other languages (like Python)

Going directly with the Rest API:

  • (+) You get to choose which libraries to use, reducing your bundle size
  • (+) You have control of how the code behaves (if you prefer OOP)
  • (-) You will require more tests, especially Integration & E2E tests
  • (-) You will lose the type definition

To make the choice and transition easier, the SDKs follow the API naming scheme (see below).

Using the SDK

Initialise the SDK

All the SDKs need to be initialized first with the API key you got from the console.

In Typescript:

    
ts
import { setupClient } from '@ansearch/sdk'; const API_KEY = process.env.API_KEY; setupClient({ apiKey: API_KEY });

In Python:

    
python
import os from astarlogic import setupClient API_KEY = os.getenv("API_KEY") setupClient(apiKey=API_KEY)

Types & schemas

The SDK has the API schemas and types, that you can use for development and runtime validation.

We use JSON schemas, in Typescript, we use the library Typebox, and in Python, we use Pydantic

Functions, models & modules naming

The SDKs follow the REST API naming scheme and TS naming convention. Each file exposes the functions, and when applicable, the models/schemas.

  • functions are in camelCase
  • schemas are in camelCase and have schema as postfix
  • Models are in PascalCase
  • Both models and schemas have their http information in their name (eg: getExampleParameters, getExampleResponse, postExampleBody)

Whenever possible, we leverage in-code documentation, so you won't have to hop between your IDE and our website.

Let's take the OAuth portal for example: There is a function to get the portal url, and later a webhook is being called. The API is located at /portal/get-url.

In Typescript with Fastify:

    
ts
import { getUrl, webhookBodySchema, type WebhookBody, } from '@ansearch/sdk/portal'; const portalUrl = await getUrl(); app.post<{ Body: WebhookBody }>( '/webhook', { schema: { body: webhookBodySchema, }, }, async (request, reply) => { // accountHint and vendor will be typed as string const { accountHint, vendor } = request.body; }, );

In Python with FastApi

    
python
from 'astarlogic.sdk.portal' import getUrl, WebhookBody portal_url = await getUrl() @app.post("/webhook") async def webhook(body: WebhookBody) -> str: # accountHint and vendor will be typed as string print(f"{body.accountHint} just connected {body.vendor}")