Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@countly/ai-sdk-core

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@countly/ai-sdk-core

Core utilities for Countly AI SDK

latest
npmnpm
Version
0.0.2
Version published
Maintainers
1
Created
Source

@countly/ai-sdk-core

Shared transport, data model, cost calculation, and event builders for the Countly AI SDK.

This is the foundation package. You usually don't install it directly — every adapter pulls it in automatically:

What it provides

  • Unified data model (RawExtractionResult) — OpenTelemetry GenAI-aligned schema produced by every adapter
  • HTTP transport — buffered POST /i with per-event device_id, retry with exponential backoff, dead-letter buffer (max 1000), 429 Retry-After support
  • Cost calculation — built-in pricing for 30+ models (OpenAI, Anthropic, Google, Cohere) with per-model override
  • Event builders[CLY]_llm_interaction, [CLY]_llm_tool_used, [CLY]_llm_tool_usage_parameter, [CLY]_llm_interaction_feedback
  • Finish reason normalization — maps provider-specific values to canonical stop | length | tool_calls | content_filter | error | other
  • Error categorizationrate_limit | context_length | content_filter | timeout | auth_error | api_error

Direct usage

If you're building a custom integration not covered by an existing adapter:

import {
  resolveConfig,
  createTransport,
  buildAllEvents,
  generatePromptId,
} from "@countly/ai-sdk-core";

const config = resolveConfig({
  appKey: "YOUR_APP_KEY",
  url: "https://your-countly-server.com",
});
const transport = createTransport(config);

const raw = {
  provider: "my-llm",
  model: "my-model",
  usage_input: 100,
  usage_output: 50,
  usage_total: 150,
  latency_total: 1200,
  status: "success" as const,
};

const events = buildAllEvents(raw, config, {
  prompt_id: generatePromptId(),
  sdk_adapter: "custom",
});
transport.enqueue(events);

Feedback events

Feedback is not auto-collected — wire it from your UI's thumbs-up/down handler:

import { buildFeedbackEvent, createTransport, resolveConfig } from "@countly/ai-sdk-core";

const config = resolveConfig({ appKey: "...", url: "..." });
const transport = createTransport(config);

function onFeedback(promptId: string, rating: string, userId: string) {
  const event = buildFeedbackEvent({ prompt_id: promptId, rating });
  event.deviceId = userId;
  transport.enqueue([event]);
}

The prompt_id links back to the [CLY]_llm_interaction event. Store it in your chat UI and read it back when the user clicks feedback.

Full documentation

See the Countly AI SDK repository for the unified data model, observability levels (0/1/2), per-user attribution via AsyncLocalStorage, cost calculation, privacy controls, and Countly plugin integration (Drill, Funnels, Cohorts, APM, Crash Analytics).

License

MIT

FAQs

Package last updated on 12 May 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts