Official open-source SDKs for the Codag hosted API.
This repository contains the Python, TypeScript, and Go clients. The SDKs call the same backend used by the Codag CLI, but they are intended for applications, agents, CI systems, and vendor backends that need to compress logs inside their own pipelines.
The SDKs live together in one repository so they share one contract snapshot, fixtures, error semantics, docs, and CI:
codag-sdk/
openapi/codag-v1.openapi.json
fixtures/
python/
typescript/
go/
The hosted API, billing system, model-serving code, and evaluation harness do
not live here. The human CLI and MCP server remain in codag-cli.
SDK v1 is API-key only.
Resolution order:
- Constructor option
CODAG_API_KEY
The default API host is https://api.codag.ai. Override it with a constructor
option or CODAG_SERVER.
SDKs do not read CLI OAuth config, launch device-flow login, or use anonymous free compact fallback. Those flows belong to the CLI.
The published packages are cut from tagged releases of this repository. Until a release is tagged you can install any SDK directly from a local checkout (see each language section). The registry commands below assume a published release:
| Language | Command | Registry |
|---|---|---|
| Python | pip install codag |
PyPI |
| TypeScript | npm install @codag/sdk |
npm |
| Go | go get github.com/codag-megalith/codag-sdk/go |
proxy |
Install a published release from PyPI:
pip install codagOr from a local checkout of this repository:
cd python
python -m pip install -e .from codag import Codag
client = Codag(api_key="cdk_...")
result = client.compact([
"ERROR api db pool timeout active=20 waiting=30 path=/api/orders",
])
print(result.text)
print(result.stats.elapsed_ms)Async convenience methods are available through AsyncCodag. They wrap the
sync implementation without adding runtime dependencies.
cd typescript
npm install @codag/sdkimport { Codag } from "@codag/sdk";
const client = new Codag({ apiKey: process.env.CODAG_API_KEY });
const result = await client.compact([
"ERROR api db pool timeout active=20 waiting=30 path=/api/orders",
]);
console.log(result.text);
console.log(result.stats.elapsed_ms);The TypeScript SDK ships as dependency-free ESM JavaScript plus .d.ts types
and uses the platform fetch implementation.
go get github.com/codag-megalith/codag-sdk/gopackage main
import (
"context"
"fmt"
"log"
codag "github.com/codag-megalith/codag-sdk/go"
)
func main() {
client := codag.New()
result, err := client.Compact(context.Background(), []string{
"ERROR api db pool timeout active=20 waiting=30 path=/api/orders",
}, nil)
if err != nil {
log.Fatal(err)
}
fmt.Println(result.Text)
}POST /v1/compactPOST /v1/capsule(Deprecated: internal/admin-only, use/v1/compact)POST /v1/compact/jobsGET /v1/compact/jobs/{job_id}GET /health
/v1/capsule is deprecated. It is now a Codag-internal, admin-only endpoint,
and non-admin callers receive a 404. Use /v1/compact instead, which is the
supported public product surface. The capsule methods and their types remain
in the SDKs for backward compatibility and internal/admin use, so existing code
keeps compiling, but they should not be used in new integrations.
Compact jobs may require a Codag Pro workspace. The SDKs surface backend 402
responses as billing errors with the upgrade path when the server provides one.
Compact jobs report status values queued, running, succeeded, or
failed. The wait_for_compact_job helpers return as soon as the job leaves
the queued/running states.
Run all local checks:
make testThe tests use only local mock servers and fixtures.
To exercise the hosted service end to end, run the opt-in live suite in all three languages:
CODAG_API_KEY=cdk_... make test-liveSet CODAG_SERVER to point the live suite at staging or a self-hosted API
instead of the hosted default.