Treg
Production Bijection component for treg.to — the OpenRouter for developer tools. Run, route, and pay for 3,000+ catalogued endpoints across 60+ providers through one API and CLI.
git clone https://github.com/bijectionhq/treg.git
cd treg
git checkout fac7dc148c0e0411a224f1c24bc33087133370c6Bijection repository access is required. Request access.
Description
Production Bijection component for treg.to — the OpenRouter for developer tools. Run, route, and pay for 3,000+ catalogued endpoints across 60+ providers through one API and CLI.
Explore the package README for API concepts, configuration, and examples. Check the Bijection source for adaptation-specific setup.
Review the source and its dependencies before adopting this package. Source availability does not establish npm publication or runtime qualification.
Getting started
- Get the source at the revision above and read its package documentation.
- Check the required Bijection SDK version, dependencies, and external service credentials.
- Follow the package setup instructions and the guide to using components.
- Exercise the component in your deployment according to your project’s verification rules.
Open source
Maintained source: bijectionhq/treg. Based on matthewdonsemail-lab/convex-treg. License: Apache-2.0. Consult the repository for license terms, notices, and contributor attribution.
From the upstream publisher
Production Convex component for treg.to — the OpenRouter for developer tools. Run, route, and pay for 3,000+ catalogued endpoints across 60+ providers through one API and CLI.
Explore the demo ↗Upstream overview
From the upstream package documentation.
A Convex component that wraps treg.to, a unified tool execution proxy providing access to 2,600+ external APIs (SpyFu, Firecrawl, SerpApi, GitHub, Stripe, Resend, and others) through a single authenticated endpoint. It runs inside Convex actions with per-call spend ceilings, SHA-256 hashed owner attribution, idempotency guarantees, and an isolated audit ledger stored in the component's own sandboxed database partition.
Use cases
From the upstream package documentation.
- Building AI agents that need to call external data APIs (SEO, SERP, domain intelligence) without embedding per-service credentials on the client or managing per-provider billing accounts
- Enforcing per-call spend caps in multi-tenant SaaS apps where individual users trigger tool executions and cost overruns must be rejected upfront before any charge occurs
- Implementing failover logic across equivalent catalog providers (e.g. SpyFu to SE Ranking to SerpApi) within a single Convex action when a provider returns 429 or 503
- Maintaining a scoped, per-user audit trail of tool invocations and costs without adding tables to the host application's own schema
- Routing LLM tool-use calls through a self-hosted or managed proxy that handles OAuth token refreshing and BYOK without exposing secrets in action arguments
How it works
From the upstream package documentation.
The component is registered in convex/convex.config.ts via app.use(treg) and declares its own isolated calls table in schema.ts for spend receipts. Required secrets (TREG_TOKEN, optionally TREG_BASE_URL) are bound at the component level using npx convex env set, so host actions never pass API credentials as function arguments.
The primary integration point is the Treg client class exported from the package root. Instantiate it once with new Treg(components.treg), then call treg.call(ctx, { owner, endpoint, params, maxCostUsd }) from any Convex action. The owner string is SHA-256 hashed server-side before being sent upstream as the customer attribution header, avoiding PII leakage. Each call also generates a fresh crypto.randomUUID() as an idempotency key and applies a 55-second AbortSignal.timeout to prevent hung actions.
Spend guardrails are enforced at the treg.to gateway layer via the X-Treg-Route-Max-Cost request header. If the estimated cost exceeds maxCostUsd, the gateway returns HTTP 402 before executing the tool and before any funds are deducted. On success, response headers (X-Treg-Call-Id, X-Treg-Cost-Micro, X-Treg-Served-Via) are written into the component's calls table.
Audit data is queryable from host application queries using treg.getCalls(ctx, { owner, limit }), which scopes results to the hashed owner. Because the calls table lives in the component's sandboxed database partition, it never conflicts with the host application's schema.
Upstream package FAQ
What is @listeningkit/treg and what does it do?
@listeningkit/treg is a Convex component that adapts treg.to, an open-source tool execution proxy and registry, for use in Convex backends. It allows Convex actions to execute over 3,000 catalogued external API endpoints across 60+ providers through a single unified API with spend controls, idempotency guarantees, and an isolated audit ledger stored in the component's own database partition.
How do I configure the treg.to API token in a Convex project?
After installing @listeningkit/treg and registering it in convex/convex.config.ts with app.use(treg), set your bearer token using npx convex env set TREG_TOKEN='your-treg-team-token'. The component declares TREG_TOKEN as a typed environment variable in its convex.config.ts, so it is injected at the component boundary without requiring callers to pass it explicitly to action handlers.
Does @listeningkit/treg conflict with my existing Convex database schema?
No. @listeningkit/treg follows the Convex component specification and defines its own encapsulated schema.ts with a calls table. This table lives in the component's isolated database partition and has no access to or visibility into the host application's tables, so there is no risk of naming conflicts or data leakage.
What version of Convex is required to use @listeningkit/treg?
The @listeningkit/treg component requires convex version 1.45.0 or higher as a peer dependency. This aligns with the Convex component specification version that introduced stable component authoring and isolated database partitions.
How does the spend ceiling work and what happens if a call exceeds it?
When calling treg.call(ctx, { maxCostUsd: 0.05, ... }), the component sets the X-Treg-Route-Max-Cost header on the outbound request to the treg.to proxy. If the proxy determines the estimated cost of executing the tool exceeds that ceiling, it returns HTTP 402 before executing the call, meaning no credits are deducted. This check happens upstream at treg.to, not client-side, making it a server-enforced guardrail.
Use with agents and CLI
Give your coding agent the component’s source identity and setup guidance.
Help me integrate Treg with Bijection.
Read: https://bijection.com/components/treg/SKILL.md
Check SDK compatibility and dependency availability.
Follow this project's execution and verification rules.Upstream README.md
View repository ↗Documentation from matthewdonsemail-lab/convex-treg, recorded October 23, 2026. APIs and setup may differ in the Bijection adaptation.
@listeningkit/treg (Convex Treg Component)
A production-ready Convex Component adapting treg — the open-source "OpenRouter for developer tools."
| Upstream engine | superdesigndev/treg (Apache-2.0) |
| Hosted registry | treg.to — 3,000+ catalogued endpoints across 60+ providers |
| CLI | treg — curl -fsSL https://treg.to/install.sh | sh |
| Community | Discord |
| Component | @listeningkit/treg on npm |
| License | Apache-2.0 (with additional terms upstream — no competing hosted registry; pass-through use of the treg.to API is fine) |
[!TIP]
🎁 Get $1.00 of Free Credits on Signup!
When you create your account at treg.to/?ref=matthewdonse-aebsh, you automatically receive $1.00 in free tool execution balance. Because catalog calls start at just ~$0.0002 per call (e.g. SpyFu, SERP, and SEO data), $1.00 gives you up to 5,000 free API calls with zero credit card required upfront! 👉 Claim your free $1 credit on treg.to here
Overview
superdesigndev/treg is an open-source tool execution proxy and registry designed as the OpenRouter for developer tools. It enables developers and AI agents to route, run, and pay for 3,000+ catalogued endpoints across 60+ external providers (including SpyFu, Firecrawl, SE Ranking, SerpApi, Perplexity, GitHub, Stripe, Resend, and more) through a single unified API, unified billing, and self-hosted proxy with BYOK, OAuth token refreshing, and per-call spend guardrails.
This package (@listeningkit/treg) provides the native, fully sandboxed Convex Component extension for treg.to. It allows any Convex backend to execute tools directly from Convex actions with zero client credentials on device, automatic spend ceilings, fresh idempotency keys, privacy-preserving attribution, and an isolated audit ledger.
Convex Component Architecture
This package is authored according to the Convex Component Specification:
treg/
├── banner.png # Visual component header banner
├── convex.config.ts # Component definition & typed environment variables
├── schema.ts # Encapsulated database schema (spend receipts ledger)
├── treg.ts # Component actions, mutations, and queries
├── client.ts # Type-safe client wrapper for host applications
├── lib/
│ └── treg.ts # Pure helper utilities (URL builder, error parser)
├── dist/ # Compiled JavaScript and TypeScript declarations
└── package.json # Component exports, peerDependencies, and scripts
1. Sandboxed Database Isolation
Components in Convex run inside an isolated boundary. The component defines its own schema.ts with a calls table. Spend receipts logged by the component remain strictly encapsulated within the component's internal database partition and never conflict with or pollute the host application's data model.
2. Typed Environment Injection
The component declares its required environment variables in convex.config.ts:
TREG_TOKEN— Your team bearer token from treg.to/?ref=matthewdonse-aebsh (sign up to get your free $1 credit!).TREG_BASE_URL— Optional base URL (defaults tohttps://treg.to).
Because these are bound in the component configuration, host action callers never need to pass API secrets as function arguments.
3. Ergonomic Client Wrapper Pattern
Directly invoking component functions via ctx.runAction(components.treg.treg.call, ...) requires tedious and fragile type assertions. This package exports a first-class Treg client wrapper class from the package root:
import { Treg } from "@listeningkit/treg";
import { components } from "./_generated/api";
export const treg = new Treg(components.treg);
The wrapper provides strongly typed methods, auto-hashing of owner identifiers, and transparent context forwarding.
Installation & Setup
1. Install the Package
Install @listeningkit/treg in your Convex application:
# npm
npm install @listeningkit/treg
# pnpm
pnpm add @listeningkit/treg
# yarn
yarn add @listeningkit/treg
(Ensure convex version >=1.45.0 is installed as a peer dependency).
2. Register the Component
Register the component inside your host application's convex/convex.config.ts:
import { defineApp } from "convex/server";
import treg from "@listeningkit/treg/convex.config";
const app = defineApp();
app.use(treg);
export default app;
3. Configure Deployment Environment Variables
Get your team token with free $1 credits from treg.to/?ref=matthewdonse-aebsh, then set it on your Convex deployment:
npx convex env set TREG_TOKEN="your-treg-team-token"
# Optional: if using a self-hosted treg instance
npx convex env set TREG_BASE_URL="https://treg.your-domain.com"
(Note: Environment variables are optional at install/codegen time so they never block local builds or type checking).
4. Regenerate Types
Run Convex codegen to generate component bindings:
npx convex dev --once
How to Use in Production
In Host Convex Actions
Wrap tool calls in your host application (e.g. convex/tools.ts) to authenticate your users, apply business logic, and forward calls to the component:
import { v } from "convex/values";
import { action } from "./_generated/server";
import { components } from "./_generated/api";
import { Treg } from "@listeningkit/treg";
// Instantiate the component client
const treg = new Treg(components.treg);
export const searchDomainCompetitors = action({
args: {
domain: v.string(),
pageSize: v.optional(v.number()),
},
handler: async (ctx, args) => {
// 1. Authenticate caller in your host app
const identity = await ctx.auth.getUserIdentity();
if (!identity) throw new Error("Unauthorized");
// 2. Call any tool catalogued on treg.to
const result = await treg.call(ctx, {
owner: identity.subject, // Automatically hashed server-side into customer attribution
endpoint: "spyfu.google.domain.competitors",
params: {
domain: args.domain,
pageSize: args.pageSize ?? 5,
},
maxCostUsd: 0.05, // Spend ceiling: treg rejects upfront if cost exceeds this reserve
});
return result;
},
});
Reading Spend Receipts & Audit Trail
Every successful tool invocation records a receipt in the component's internal calls table using the response headers (X-Treg-Call-Id, X-Treg-Cost-Micro, and X-Treg-Served-Via).
To query the logged receipts from your host application:
import { query } from "./_generated/server";
import { components } from "./_generated/api";
import { Treg } from "@listeningkit/treg";
const treg = new Treg(components.treg);
export const getMyToolUsage = query({
args: {},
handler: async (ctx) => {
const identity = await ctx.auth.getUserIdentity();
if (!identity) throw new Error("Unauthorized");
// Returns recent receipts for this user
return await treg.getCalls(ctx, {
owner: identity.subject,
limit: 20,
});
},
});
Production Guardrails
| Guardrail | Mechanism | Benefit |
|---|---|---|
| Max Cost Ceiling | X-Treg-Route-Max-Cost header | Treg refuses the call upfront (HTTP 402) if reserve exceeds max cost; zero funds charged. |
| Idempotency Guarantee | Fresh crypto.randomUUID() header per call | Upstream retries or network replays are never double-billed. |
| Privacy Attribution | SHA-256 hashed owner (customer=<hash>) | Per-tenant spend ledger and multi-tenant scoping without leaking raw user IDs or PII upstream. |
| Audit Ledger | Isolated calls table in component schema | Automatically stores callId, ownerHash, endpoint, costMicro, servedVia, and at. |
| Fail-Safe Timeout | AbortSignal.timeout(55_000) | Prevents hung actions from consuming backend execution budget. |
Catalog, Costs & Failover Strategy
Sign up at treg.to/?ref=matthewdonse-aebsh to get $1.00 free credit, which covers thousands of calls across 3,000+ catalogued endpoints on 60+ providers.
Search the full catalog at treg.to/catalog or via the unauthenticated search API:
curl "https://treg.to/catalog/search?q=competitors"
Failover Pattern Example (SEO Competitors)
When building resilient AI workflows, implement failover between provider rows:
| Provider | Endpoint ID | Approx. Cost | Free Calls from $1 Credit | Role |
|---|---|---|---|---|
| SpyFu | spyfu.google.domain.competitors | ~$0.0002 / row | ~5,000 calls | Primary (fast, keyword-overlap ranking) |
| SE Ranking | seranking.google.domain.competitors | ~$0.0179 / call | ~55 calls | Failover (rich metrics: domain relevance, traffic) |
| SerpApi | serpstat.google.domain.competitors | ~$0.0005 / result | ~2,000 calls | Alternate |
Failover Policy: On HTTP
429(rate limit),503(provider temporarily down), or timeout, retry with the next catalog provider row. Never failover on4xxclient errors (invalid domain/parameters will fail across all providers and waste credit).
Component Development & Publishing
Build from Source
# Install dependencies
pnpm install
# Compile TypeScript declarations and JavaScript bundles
pnpm run build
# Type check
pnpm run typecheck
# Run tests
pnpm test
Publishing to NPM
- Ensure clean build and type generation:
pnpm run build:clean - Publish to npm:
npm publish --access public - Submit to the official Convex Components Directory.
Free Signup Link
Don't forget to grab your $1.00 free tool credit when getting started: 👉 Sign up on treg.to (?ref=matthewdonse-aebsh)
License
Apache 2.0. See superdesigndev/treg for upstream engine details (including its additional terms: use freely, even commercially; pass-through use of the treg.to API is allowed; don't redistribute the code as a competing hosted registry without written permission).
Support
If this is useful, a star helps someone else find it.