Skip to main content
Paste this prompt into your coding agent (Claude Code, Cursor, or similar) from inside your project:
If you just created an API key in the dashboard, the key panel has a Copy prompt for your AI agent button that produces this prompt with your key pre-filled. Everything below this line is written for the agent.

Agent instructions

You are integrating Pylva, cost infrastructure for AI agent businesses. The SDK meters the host application’s LLM and non-LLM usage per customer and per agent step, and reports cost-shaped telemetry. Rules to follow throughout:
  • Never print, log, or commit the Pylva API key. Store it in the project’s secret store or .env, and make sure .env is gitignored.
  • Never send prompt text, completions, tool arguments, message bodies, emails, or phone numbers in telemetry. Use opaque customer_id values and stable step labels.
  • Pylva instrumentation must fail open: do not let it break the host application.
  • The full documentation index is at https://docs.pylva.com/llms.txt. You can also connect the docs MCP server: claude mcp add --transport http pylva-docs https://docs.pylva.com/mcp.

Step 1 - Detect the stack

Inspect the project and choose one integration mode:

Step 2 - HUMAN ACTION: account and API key

Tell your human exactly this, then wait:
I need a Pylva API key.
  1. Open https://pylva.com/pricing and choose Pro or Scale. Both include a 14-day trial. Enterprise requires contacting sales.
  2. Sign in with GitHub, Google, or an email magic link and complete Stripe Checkout. The workspace cannot create keys or ingest events until a plan is active.
  3. Open https://pylva.com/settings/keys (after sign-in it lands on Settings -> API keys). You must be the workspace owner.
  4. Click Create key and create it.
  5. Copy the key immediately - it is shown only once. Put it in .env as PYLVA_API_KEY=pv_live_... (or paste it to me and I will store it there).
After Checkout activates the workspace, its Get started dashboard checklist also offers a one-click Create API key shortcut.

Step 3 - Validate the key

Before writing any code:
  1. Check the format: ^pv_(live|cli)_[a-f0-9]{8}_[a-f0-9]{32}$. New keys use pv_live_*; legacy pv_cli_* keys remain valid after the universal-key migration.
  2. Check it live (this endpoint is a safe read):
200 means the key is valid. 401 means it is not - re-ask the human (a typo or a revoked key; the body is {"error":{"code":"INVALID_API_KEY",...}}). 403 WRONG_SCOPE only appears on older deployments that still enforce legacy key scopes. For a richer check, GET https://api.pylva.com/api/v1/whoami with the same headers returns the workspace, plan, access state, and current usage in one call - see Who am I.

Step 4 - Install and wire the SDK

The SDK does not read environment variables automatically - always pass the key explicitly from the environment.

TypeScript

Python

Wiring guidance:
  • Find where the application already knows which customer a request belongs to, and wrap at that boundary. Use the application’s stable internal user/account ID as customer_id (opaque, [A-Za-z0-9_-], max 255 chars) - never an email.
  • Use a small set of stable step labels named after workflow stages (retrieve_context, draft, evaluate), not per-request values.
  • Self-hosted Pylva: pass endpoint: "https://<your-host>" / endpoint="https://<your-host>" to init.

Step 5 - Verify end to end

  1. Optionally prove ingest works before running the app - send one zero-cost test event:
Expected response: {"accepted":1,"rejected":0}. Every field above is required - the API rejects partial events. The full schema is at https://api.pylva.com/openapi.json.
  1. Run the instrumented code path once for a real (test) customer. The SDK flushes about every 5 seconds; for a short script, flush before exit: await flush() (TypeScript) / await pylva.flush() (Python, or asyncio.run(pylva.flush()) in sync scripts).
  2. Tell the human:
Open your Pylva dashboard - once the first event arrives, the “Get started” checklist is replaced by live cost data. You should see customer setup-test (and your real test customer) with the steps we instrumented.
If no event appears, work through Troubleshooting.

Step 6 - Production checklist

  • Confirm no prompts, completions, or PII are sent in any metadata you added (Privacy and PII).
  • If the project has non-LLM costs (search, speech, vector DBs), see Non-LLM Usage and tell the human which pricing rules to configure in the dashboard.
  • Before enabling budget hard stops, read Budget Enforcement and Controls Workflow.

Step 7 - HUMAN ACTION: plan changes

When usage approaches the current plan cap, tell the human to review Plans and limits and open https://pylva.com/pricing. Pro is 49/monthfor1MeventsandScaleis49/month for 1M events and Scale is 199/month for 10M events. Enterprise is contact-sales only. Checkout and plan changes happen in the browser. Never ask the human for card details.