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,
});
| Setting | Python | TypeScript | Environment variable | Default |
|---|---|---|---|---|
| API key | api_key | apiKey | MODAIC_API_KEY | Required |
| Base URL | base_url | baseUrl | MODAIC_API_URL | https://modaic.dev/api/v1 |
| Request timeout | timeout | timeoutMs | — | 30 seconds |
| Fetch implementation | — | fetch | — | globalThis.fetch |
For a local API server, set the base URL to http://localhost:3001/v1.
Resources
| Concept | Python | TypeScript |
|---|---|---|
| Decisions | modaic.decisions | modaic.decisions |
| Models | modaic.models | modaic.models |
| Examples | modaic.examples | modaic.examples |
| Batch decisions | modaic.batch_decisions | modaic.batchDecisions |
| Alignments | modaic.alignments | modaic.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.