Search Modaic documentation

Find a Modaic guide or API reference

SDK installation

Modaic's Python and TypeScript SDKs are typed, HTTP-only clients for the public API. They do not interact with Git or read and write repository files.

Install

npm install modaic

Python requires version 3.11 or later and includes matching synchronous and asynchronous clients. TypeScript requires Node.js 18 or later, uses the standard Fetch API, and has no runtime dependencies.

Create an API key in the Modaic dashboard, then export it:

export MODAIC_API_KEY="mdc_..."

Create a client

import { Modaic } from "modaic";

const modaic = new Modaic();
const models = await modaic.models.list();

console.log(models.models.map((model) => model.name));

Python responses are Pydantic models. TypeScript methods return promises and export their request and response types from the package.

Async Python

AsyncModaic exposes the same resources and method names as the synchronous client:

import asyncio

from modaic import AsyncModaic


async def main() -> None:
    async with AsyncModaic() as modaic:
        models = await modaic.models.list()
        print([model.name for model in models.models])


asyncio.run(main())

Configuration

import { Modaic } from "modaic";

const modaic = new Modaic({
  apiKey: "mdc_...",
  baseUrl: "https://modaic.dev/api/v1",
  timeoutMs: 30_000,
});
SettingPythonTypeScriptEnvironment variableDefault
API keyapi_keyapiKeyMODAIC_API_KEYRequired
Base URLbase_urlbaseUrlMODAIC_API_URLhttps://modaic.dev/api/v1
Request timeouttimeouttimeoutMs—30 seconds
Fetch implementation—fetch—globalThis.fetch

For a local API server, set the base URL to http://localhost:3001/v1.

Resources

ConceptPythonTypeScript
Decisionsmodaic.decisionsmodaic.decisions
Modelsmodaic.modelsmodaic.models
Examplesmodaic.examplesmodaic.examples
Batch decisionsmodaic.batch_decisionsmodaic.batchDecisions
Alignmentsmodaic.alignmentsmodaic.alignments

Errors

import { Modaic, ModaicAPIError } from "modaic";

try {
  await new Modaic().models.list();
} catch (error) {
  if (error instanceof ModaicAPIError) {
    console.error(error.status, error.code, error.requestId);
  }
}

API responses raise or throw ModaicAPIError. Connection failures use ModaicConnectionError; request and polling deadlines use ModaicTimeoutError.

Was this page helpful?