Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions skill/reference/axiom.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
# Axiom API Capabilities

Summary of all operations available via Axiom API with a personal access token (PAT).
Summary of all operations available via Axiom API.

**Base URL:** `https://api.axiom.co` (for all endpoints except ingestion)
**Ingest URL:** Use edge deployment domain (e.g., `https://us-east-1.aws.edge.axiom.co`)
**Base URL:** `https://api.axiom.co` (for management endpoints)
**Query & Ingest URL:** Auto-resolved per dataset via `scripts/resolve-url`

**Authentication:**
- PAT: `Authorization: Bearer $PAT` + `x-axiom-org-id: $ORG_ID`
- API Token: `Authorization: Bearer $API_TOKEN`
- `Authorization: Bearer $API_TOKEN` — use an advanced API token with minimal privileges

---

Expand Down
28 changes: 26 additions & 2 deletions skill/scripts/axiom-api
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,32 @@ fi
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
eval "$("$SCRIPT_DIR/config" axiom "$DEPLOYMENT")"

# Auto-resolve edge URL for query and ingest endpoints
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain what's going on here? Why do we need to auto-resolve anything? Why don't we use the configured axiom url directly?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because core APIs for ingest and query will be deprecated as part of multiregion, we're moving to route those directly to the edge endpoint. This also correctly handles multi region ds, since queries go to the right regional edge

REQUEST_URL="$AXIOM_URL"
REQUEST_ENDPOINT="$ENDPOINT"
case "$ENDPOINT" in
/v1/datasets/_apl*|/v1/ingest/*)
DATASET=""
if [[ "$ENDPOINT" == /v1/ingest/* ]]; then
DATASET="${ENDPOINT#/v1/ingest/}"
DATASET="${DATASET%%[?/]*}"
elif [[ -n "$BODY" ]]; then
DATASET=$(echo "$BODY" | jq -r '.apl // empty' 2>/dev/null | grep -oE "^\['[^']+'\]|^\[\"[^\"]+\"\]|^\[[a-zA-Z0-9_-]+\]" | head -1 | tr -d "[]'\"" || true)
Comment thread
tsenart marked this conversation as resolved.
Outdated
fi
if [[ -n "$DATASET" ]]; then
RESOLVED=$("$SCRIPT_DIR/resolve-url" "$DEPLOYMENT" "$DATASET" 2>/dev/null || true)
if [[ -n "$RESOLVED" && "$RESOLVED" != "$AXIOM_URL" ]]; then
REQUEST_URL="$RESOLVED"
if [[ "$ENDPOINT" == /v1/datasets/_apl* ]]; then
REQUEST_ENDPOINT="/v1/query/_apl${ENDPOINT#/v1/datasets/_apl}"
fi
fi
fi
;;
esac

if [[ -n "$BODY" ]]; then
"$SCRIPT_DIR/curl-auth" axiom "$DEPLOYMENT" -X "$METHOD" -d "$BODY" "${AXIOM_URL}${ENDPOINT}"
"$SCRIPT_DIR/curl-auth" axiom "$DEPLOYMENT" -X "$METHOD" -d "$BODY" "${REQUEST_URL}${REQUEST_ENDPOINT}"
else
"$SCRIPT_DIR/curl-auth" axiom "$DEPLOYMENT" -X "$METHOD" "${AXIOM_URL}${ENDPOINT}"
"$SCRIPT_DIR/curl-auth" axiom "$DEPLOYMENT" -X "$METHOD" "${REQUEST_URL}${REQUEST_ENDPOINT}"
fi
2 changes: 1 addition & 1 deletion skill/scripts/axiom-link
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ fi
# Derive web UI URL from configured API URL
# Replace "api." with "app." in the domain
# Examples:
# https://api.axiom.co → https://app.axiom.co
# https://api.staging.axiom.co → https://app.staging.axiom.co
# https://api.dev.axiom.co → https://app.dev.axiom.co
# https://cloud.axiom.co → https://app.axiom.co
# https://api.axiom.co → https://app.axiom.co
if [[ "$URL" == *"cloud.axiom.co"* ]]; then
BASE_URL="https://app.axiom.co"
elif [[ "$URL" == https://api.* ]]; then
Expand Down
14 changes: 13 additions & 1 deletion skill/scripts/axiom-query
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,18 @@ PAYLOAD=$(jq -cn \
# shellcheck disable=SC1090
eval "$("$SCRIPT_DIR/config" axiom "$DEPLOYMENT")"

# Auto-resolve edge URL
QUERY_URL="$AXIOM_URL"
QUERY_PATH="/v1/datasets/_apl?format=tabular"
DATASET=$(echo "$APL" | grep -oE "^\['[^']+'\]|^\[\"[^\"]+\"\]|^\[[a-zA-Z0-9_-]+\]" | head -1 | tr -d "[]'\"" || true)
Comment thread
aisha331 marked this conversation as resolved.
Outdated
if [[ -n "$DATASET" ]]; then
RESOLVED=$("$SCRIPT_DIR/resolve-url" "$DEPLOYMENT" "$DATASET" 2>/dev/null || true)
if [[ -n "$RESOLVED" && "$RESOLVED" != "$AXIOM_URL" ]]; then
QUERY_URL="$RESOLVED"
QUERY_PATH="/v1/query/_apl?format=tabular"
fi
fi

RESP_HEADERS=$(mktemp)
RESP_BODY=$(mktemp)
cleanup() {
Expand All @@ -150,7 +162,7 @@ trap cleanup EXIT

# Execute query and pipe to formatter
HTTP_CODE=$(curl -sS -o "$RESP_BODY" -D "$RESP_HEADERS" -w "%{http_code}" \
-X POST "$AXIOM_URL/v1/datasets/_apl?format=tabular" \
-X POST "$QUERY_URL$QUERY_PATH" \
-H "Authorization: Bearer $AXIOM_TOKEN" \
-H "X-Axiom-Org-Id: $AXIOM_ORG_ID" \
-H "Content-Type: application/json" \
Expand Down
99 changes: 99 additions & 0 deletions skill/scripts/resolve-url
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#!/usr/bin/env bash
# resolve-url: Resolve the regional edge URL for a dataset
#
# Usage: resolve-url <deployment> <dataset>
#
# Two-step resolution:
# 1. GET /v1/datasets → find dataset's region (e.g. cloud.us-east-1.aws)
# 2. GET /api/internal/regions/axiom → map region to edge domain
#
# Both steps are cached to avoid repeated API calls.

set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

DEPLOYMENT="${1:-}"
DATASET="${2:-}"

if [[ -z "$DEPLOYMENT" || -z "$DATASET" ]]; then
echo "Usage: resolve-url <deployment> <dataset>" >&2
exit 1
fi

CACHE_DIR="${TMPDIR:-/tmp}/axiom-edge-cache"

# Check dataset edge URL cache (valid for 1 hour)
DATASET_CACHE="$CACHE_DIR/edge__${DEPLOYMENT}__${DATASET}"
if [[ -f "$DATASET_CACHE" ]]; then
if [[ "$(uname)" == "Darwin" ]]; then
AGE=$(( $(date +%s) - $(stat -f %m "$DATASET_CACHE") ))
else
AGE=$(( $(date +%s) - $(stat -c %Y "$DATASET_CACHE") ))
fi
if [[ $AGE -lt 3600 ]]; then
cat "$DATASET_CACHE"
exit 0
fi
fi

eval "$("$SCRIPT_DIR/config" axiom "$DEPLOYMENT")"

# Step 1: get dataset region
REGION=$("$SCRIPT_DIR/curl-auth" axiom "$DEPLOYMENT" -X GET "${AXIOM_URL}/v1/datasets" \
| jq -r --arg name "$DATASET" '.[] | select(.name == $name) | .edgeDeployment // .region // empty' 2>/dev/null)

if [[ -z "$REGION" || "$REGION" == "null" ]]; then
mkdir -p "$CACHE_DIR"
echo "$AXIOM_URL" > "$DATASET_CACHE"
echo "$AXIOM_URL"
exit 0
fi
Comment thread
aisha331 marked this conversation as resolved.

# Step 2: look up edge domain from regions API (cached 24h per deployment)
REGIONS_CACHE="$CACHE_DIR/regions__${DEPLOYMENT}"
REGIONS_JSON=""
if [[ -f "$REGIONS_CACHE" ]]; then
if [[ "$(uname)" == "Darwin" ]]; then
AGE=$(( $(date +%s) - $(stat -f %m "$REGIONS_CACHE") ))
else
AGE=$(( $(date +%s) - $(stat -c %Y "$REGIONS_CACHE") ))
fi
if [[ $AGE -lt 86400 ]]; then
REGIONS_JSON=$(cat "$REGIONS_CACHE")
fi
fi

if [[ -z "$REGIONS_JSON" ]]; then
if [[ "$AXIOM_URL" == *"cloud.axiom.co"* ]]; then
APP_URL="https://app.axiom.co"
else
APP_URL="${AXIOM_URL/api./app.}"
fi
Comment thread
aisha331 marked this conversation as resolved.
REGIONS_JSON=$("$SCRIPT_DIR/curl-auth" axiom "$DEPLOYMENT" -X GET "${APP_URL}/api/internal/regions/axiom" 2>/dev/null) || true
if [[ -n "$REGIONS_JSON" ]]; then
mkdir -p "$CACHE_DIR"
echo "$REGIONS_JSON" > "$REGIONS_CACHE"
fi
Comment thread
aisha331 marked this conversation as resolved.
fi

EDGE_DOMAIN=""
if [[ -n "$REGIONS_JSON" ]]; then
EDGE_DOMAIN=$(echo "$REGIONS_JSON" | jq -r --arg region "$REGION" '.axiom[] | select(.id == $region) | .domain // empty' 2>/dev/null)
fi

if [[ -z "$EDGE_DOMAIN" ]]; then
mkdir -p "$CACHE_DIR"
echo "$AXIOM_URL" > "$DATASET_CACHE"
echo "$AXIOM_URL"
exit 0
fi

# Cache the resolved edge URL
mkdir -p "$CACHE_DIR"
if [[ "$EDGE_DOMAIN" != https://* ]]; then
EDGE_DOMAIN="https://${EDGE_DOMAIN}"
fi
echo "$EDGE_DOMAIN" > "$DATASET_CACHE"

echo "$EDGE_DOMAIN"
Loading