DEV Community

Alex Spinov
Alex Spinov

Posted on

Axiom Has a Free API: Here's How to Query and Analyze Your Logs Programmatically

What is Axiom?

Axiom is a modern log management and analytics platform that handles petabytes of data with zero configuration. Unlike traditional logging tools, Axiom stores everything and lets you query it in real-time.

The free tier gives you 500 GB/month of ingest — and the API is fully open for programmatic access.

Getting Started

npm install @axiomhq/js
Enter fullscreen mode Exit fullscreen mode

Send Logs

import { Axiom } from "@axiomhq/js";

const axiom = new Axiom({
  token: process.env.AXIOM_TOKEN,
  orgId: process.env.AXIOM_ORG_ID,
});

await axiom.ingest("my-app-logs", [
  {
    level: "info",
    message: "User signed up",
    userId: "usr_123",
    plan: "pro",
    _time: new Date().toISOString(),
  },
  {
    level: "error",
    message: "Payment failed",
    userId: "usr_456",
    error: "card_declined",
    _time: new Date().toISOString(),
  },
]);

await axiom.flush();
Enter fullscreen mode Exit fullscreen mode

Query with APL (Axiom Processing Language)

const result = await axiom.query(
  `["my-app-logs"]
  | where level == "error"
  | where _time > ago(1h)
  | project _time, message, error, userId
  | sort by _time desc`
);

console.log(result.matches);
Enter fullscreen mode Exit fullscreen mode

Aggregations

const errorRate = await axiom.query(
  `["my-app-logs"]
  | where _time > ago(24h)
  | summarize
      total = count(),
      errors = countif(level == "error")
      by bin(_time, 1h)
  | extend error_rate = round(toreal(errors) / toreal(total) * 100, 2)
  | sort by _time asc`
);

const topErrors = await axiom.query(
  `["my-app-logs"]
  | where level == "error"
  | where _time > ago(7d)
  | summarize count() by message
  | sort by count_ desc`
);
Enter fullscreen mode Exit fullscreen mode

REST API

curl -X POST "https://api.axiom.co/v1/datasets/my-dataset/ingest" \
  -H "Authorization: Bearer $AXIOM_TOKEN" \
  -H "Content-Type: application/json" \
  -d '[{"message": "hello", "level": "info"}]'
Enter fullscreen mode Exit fullscreen mode

Next.js Integration

import { Logger } from "@axiomhq/js";

export const logger = new Logger({
  token: process.env.AXIOM_TOKEN,
  dataset: "next-app",
});

// In API routes:
export async function POST(req) {
  logger.info("API called", { path: "/api/users" });
  try {
    const user = await createUser(await req.json());
    logger.info("User created", { userId: user.id });
    return Response.json(user);
  } catch (error) {
    logger.error("User creation failed", { error: error.message });
    return Response.json({ error: "Failed" }, { status: 500 });
  }
}
Enter fullscreen mode Exit fullscreen mode

Vercel Integration

npx @axiomhq/cli vercel setup
Enter fullscreen mode Exit fullscreen mode

All Vercel logs automatically flow to Axiom.

Free Tier

Feature Free Pro
Ingest 500 GB/mo 1 TB+
Retention 30 days Custom
Users 1 Unlimited
API Access Full Full

500 GB/month is enough for most startups.


Need help with logging, monitoring, or data pipeline automation?

📧 spinov001@gmail.com
🔧 My tools on Apify Store

What logging stack do you use? Drop a comment!

Top comments (0)