You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: AGENTS.md
+7-6Lines changed: 7 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
## Product Overview
4
4
5
-
[Apitally](https://apitally.io) is an API monitoring and analytics tool. This is a CLI tool for humans and AI agents. It retrieves data from the Apitally API and outputs it in NDJSON format, or optionally stores it in a local DuckDB database and allows running arbitrary SQL queries against it.
5
+
[Apitally](https://apitally.io) is an API monitoring and analytics tool. This is a CLI tool for AI agents and humans. It retrieves data from the Apitally API and outputs it in NDJSON format, or optionally stores it in a local DuckDB database and allows running arbitrary SQL queries against it.
6
6
7
7
## Repository Structure
8
8
@@ -20,6 +20,10 @@ src/
20
20
npm/
21
21
cli.js Thin wrapper that spawns the native binary
22
22
install.js postinstall script that downloads the correct binary
23
+
skills/
24
+
apitally-cli/ Agent skill: guides AI agents through using the CLI to investigate API issues
references/ Detailed command and table schema references
23
27
```
24
28
25
29
## Tech Stack
@@ -82,7 +86,7 @@ Triggered by publishing a GitHub release. Two jobs:
82
86
83
87
### Module `run()` functions
84
88
85
-
Each command module exposes a `pub fn run(...)` that does all the work: resolve auth, call the API, write output. The last parameter is always `impl Write` (stdout in production, `Vec<u8>` in tests). Data goes to the writer (stdout), human messages and progress go to stderr.
89
+
Each command module exposes a `pub fn run(...)` that does all the work: resolve auth, call the API, write output. The last parameter is `impl Write` (stdout in production, `Vec<u8>` in tests), except `auth::run` which takes `&mut impl Read` (stdin) instead. Data goes to the writer (stdout), human messages and progress go to stderr.
86
90
87
91
### Error handling and exit codes
88
92
@@ -100,10 +104,6 @@ Exit code 2 comes from clap (usage errors). `check_response` in `utils.rs` centr
100
104
101
105
API requests use `api_get`/`api_post` helpers in `utils.rs`. API key is sent as the `Api-Key` header.
102
106
103
-
### request-logs dual format
104
-
105
-
The `request-logs` command sends `format: "ndjson"` or `format: "arrow"` depending on whether `--db` is given. NDJSON mode is a raw passthrough (`io::copy` from response to stdout). Arrow mode streams Arrow IPC batches into a DuckDB staging table, then does `INSERT OR REPLACE` into the final table.
106
-
107
107
## Tests
108
108
109
109
Inline `#[cfg(test)] mod tests` in each source file. Run with `cargo test`.
@@ -123,3 +123,4 @@ Inline `#[cfg(test)] mod tests` in each source file. Run with `cargo test`.
123
123
- Verify work compiles and passes `cargo clippy` before considering a task complete
124
124
- Keep user-facing output concise
125
125
- Use inline comments sparingly — only to explain non-obvious intent
126
+
- When changing CLI commands, flags, output format, or DuckDB schemas, update the agent skill in `skills/apitally-cli/` (including its `references/` docs) to reflect those changes
Copy file name to clipboardExpand all lines: skills/apitally-cli/SKILL.md
+27-71Lines changed: 27 additions & 71 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,25 +11,45 @@ description: >
11
11
12
12
# Apitally CLI
13
13
14
-
The Apitally CLI retrieves API request log data from [Apitally](https://apitally.io) and optionally stores it in a local DuckDB database for investigation with SQL. Each record is an individual API request with method, URL, status code, response time, consumer, headers, payloads, exceptions, and more. Request log retention is **15 days**. Older data is not available.
14
+
The Apitally CLI retrieves API request log data from [Apitally](https://apitally.io) and optionally stores it in a local DuckDB database for investigation with SQL. Each record is an individual API request with method, URL, status code, response time, consumer, headers, payloads, exceptions, and more. Request log retention is **15 days**.
15
15
16
-
Run commands with npx (no install needed):
16
+
Run commands with `npx` (no install needed):
17
17
18
18
```
19
19
npx @apitally/cli <command> [--api-key <key>]
20
20
```
21
21
22
+
A team-scoped API key is required to use the CLI. The `auth` command writes the provided API key to `~/.apitally/auth.json`. It's then used by all subsequent commands unless overridden by the `--api-key` flag.
23
+
22
24
All commands output NDJSON to stdout by default. With `--db`, data is written to a DuckDB database instead (`~/.apitally/data.duckdb` by default), enabling SQL queries via the `sql` command.
23
25
24
-
A team-scoped API key is required to use the CLI. The `auth` command writes the provided API key to `~/.apitally/auth.json`. It's then used by all subsequent commands unless overridden by the `--api-key` flag.
26
+
## Key Concepts
27
+
28
+
-**App and environment** — An app is a monitored API application, identified by a numeric `app_id`. Each app has one or more environments (e.g. "prod", "dev"). The `env` field on request logs is a string matching the environment name.
29
+
-**Consumer** — An API client or user tracked by Apitally. `consumer_id` is a numeric internal ID (surrogate key, used in request log filters and JOINs). `identifier` is a string set by the application (e.g. email, username) to uniquely identify the consumer. `name` is a display name (auto-generated from `identifier` if not explicitly set). `group` is an optional group name.
30
+
-**Path vs URL** — `path` is the parameterized route template (e.g. `/users/{user_id}`), good for grouping by endpoint. `url` is the full request URL with actual values and query parameters (e.g. `https://api.example.com/users/123?limit=10`).
31
+
-**Application logs** — Server-side log entries emitted by application code during request handling. Only available via `request-details` as the `logs` field.
32
+
-**Spans** — OpenTelemetry trace spans representing units of work during request handling (e.g. database queries, external API calls, instrumented function calls). Only available via `request-details`. Form a tree via `parent_span_id`.
33
+
34
+
## Command Quick Reference
35
+
36
+
All commands are run via `npx @apitally/cli <command>`. For full details, see [references/commands.md](references/commands.md).
37
+
38
+
-`auth [--api-key <key>]` -- configure API key
39
+
-`whoami` -- check auth, show team
40
+
-`apps [--db [<path>]]` -- list apps (get app IDs)
41
+
-`consumers <app-id> [--requests-since <dt>] [--db [<path>]]` -- list consumers for an app (get consumer IDs)
-`request-details <app-id> <request-uuid> [--db [<path>]]` -- fetch full details for a single request (including headers, payloads, exception info, application logs, and spans)
44
+
-`sql "<query>" [--db <path>]` -- run SQL against local DuckDB
25
45
26
46
## Workflow
27
47
28
-
1.**Check authentication**-- run `npx @apitally/cli whoami`. If it fails, ask the user to provide their Apitally API key or run `npx @apitally/cli auth` themselves. Explain that API keys can be created in the Apitally dashboard under Settings > API keys (https://app.apitally.io/settings/api-keys). If the user provides a key, run `npx @apitally/cli auth --api-key <key>` to store it.
48
+
1.**Check authentication**— run `npx @apitally/cli whoami`. If it fails, ask the user to provide their Apitally API key or run `npx @apitally/cli auth` themselves. Explain that API keys can be created in the Apitally dashboard under Settings > API keys (https://app.apitally.io/settings/api-keys). If the user provides a key, run `npx @apitally/cli auth --api-key <key>` to store it.
29
49
30
-
2.**Identify the app**-- run `npx @apitally/cli apps` to list apps and get their IDs. If there is only one app, use it. Otherwise, if the correct app can't be inferred from the user's previous messages, ask the user which app they mean.
50
+
2.**Identify the app**— run `npx @apitally/cli apps` to list apps and get their IDs. If there is more than one app, and the correct app can't be inferred from the user's messages, ask the user which app they mean.
31
51
32
-
3.**Determine if consumers are involved**-- decide which scenario applies:
52
+
3.**Determine if consumers are involved**— decide which scenario applies:
33
53
-**(a) Specific consumer(s)**: the user is asking about specific consumers (e.g. by email, name, or group). Fetch consumers first, then query to find the matching `consumer_id`, then use it as a filter when fetching request logs.
34
54
-**(b) Consumer context needed**: the investigation involves consumers but not specific ones known upfront (e.g. "which consumers cause the most errors"). Fetch consumers into DuckDB for later JOINs with request logs.
35
55
-**(c) No consumer involvement**: skip fetching consumers.
@@ -65,66 +85,12 @@ A team-scoped API key is required to use the CLI. The `auth` command writes the
65
85
npx @apitally/cli sql "SELECT method, path, status_code, COUNT(*) as n FROM request_logs WHERE status_code >= 400 GROUP BY ALL ORDER BY n DESC"
66
86
```
67
87
68
-
7.**Iterate** -- refine filters, fetch additional fields (headers, bodies, exceptions), or widen the time range as needed
69
-
70
-
## Command Quick Reference
71
-
72
-
All commands are run via `npx @apitally/cli <command>`. For full details, see [references/commands.md](references/commands.md).
73
-
74
-
-`auth [--api-key <key>]` -- configure API key
75
-
-`whoami` -- check auth, show team
76
-
-`apps [--db [<path>]]` -- list apps (get app IDs)
77
-
-`consumers <app-id> [--requests-since <dt>] [--db [<path>]]` -- list consumers for an app
0 commit comments