Codag
Sign in
SDKs

SDKs for Python, TypeScript, and Go

Compress logs from your own applications, agents, and CI in Python, TypeScript, or Go.

Official open-source clients for Python, TypeScript, and Go. They call the same compact API as the CLI, but they are built for applications, agents, CI systems, and vendor backends that compress logs inside their own pipelines. Same contract, same errors, one idiomatic client per language.

Python

codag

$pip install codag

TypeScript

@codag/sdk

$npm install @codag/sdk

Go

codag-sdk/go

$go get github.com/codag-megalith/codag-sdk/go

Compress a batch of logs

Pass a list of log lines and get back compact, line-referenced evidence text plus parse stats. Each client reads its API key from the constructor or the CODAG_API_KEY environment variable.

from codag import Codag

client = Codag()  # reads CODAG_API_KEY

result = client.compact([
    "ERROR api db pool timeout active=20 waiting=30 path=/api/orders",
    "WARN api db pool nearing capacity active=18",
])

print(result.text)
print(result.stats.elapsed_ms)
import { Codag } from "@codag/sdk";

const client = new Codag();  // reads CODAG_API_KEY

const result = await client.compact([
  "ERROR api db pool timeout active=20 waiting=30 path=/api/orders",
  "WARN api db pool nearing capacity active=18",
]);

console.log(result.text);
console.log(result.stats.elapsed_ms);
package main

import (
    "context"
    "fmt"
    "log"

    codag "github.com/codag-megalith/codag-sdk/go"
)

func main() {
    client := codag.New()  // reads CODAG_API_KEY

    result, err := client.Compact(context.Background(), []string{
        "ERROR api db pool timeout active=20 waiting=30 path=/api/orders",
        "WARN api db pool nearing capacity active=18",
    }, nil)
    if err != nil {
        log.Fatal(err)
    }

    fmt.Println(result.Text)
    fmt.Println(result.Stats.ElapsedMS)
}

result.text is the compact evidence view: the lines that matter, each pointing back to a real log line number. result.stats carries the parse counters, including elapsed_ms and cache hits, so you can log how much a call did.

Configuration

Credentials resolve from the constructor first, then CODAG_API_KEY. The default host is https://api.codag.ai; override it with a constructor option or CODAG_SERVER to target staging or a self-hosted API. Keys are sent as bearer tokens over HTTPS.

Errors

Non-2xx responses raise typed errors so you can branch on the case that matters:

  • Authentication (401): missing, invalid, or rejected key.
  • Billing (402): the action needs a Codag Pro workspace. The error carries the upgrade path when the server provides one.
  • Rate limit (429): the error carries the retry-after hint.
  • Validation: raised before any request when input cannot be sent safely (empty batch, oversized line).

Python and TypeScript raise exception classes (AuthenticationError, BillingError, RateLimitError, ValidationError). Go returns an *APIError with a StatusCode, and sentinel values (ErrAuthentication, ErrBilling, ErrRateLimited) you match with errors.Is.

Large batches

For big log windows, submit an async job and poll for the result instead of blocking one request. Each client exposes a create call and a wait helper (create_compact_job and wait_for_compact_job in Python, createCompactJob and waitForCompactJob in TypeScript, CreateCompactJob and WaitForCompactJob in Go) that return once the job leaves the queued or running state.

Resources