BazaarLinkBazaarLink
Sign in
← All articles
Published 2026-05-01 · · Author:BazaarLink · AI Agents · API Key Management · LangChain · CrewAI · AutoGen · Multi-Agent

AI Agents Self-Register and Provision Their Own API Keys

Agents self-register an API key at https://bazaarlink.ai/api/v1/agents/register, or a Management API Key issues capped keys. LangChain, CrewAI, AutoGen.

Updated 2026-10-01. Agent self-registration is open again: an agent can call POST https://bazaarlink.ai/api/v1/agents/register and get its own API key. For per-key spend caps and expiry set centrally, you can still provision keys with a Management API Key. This guide covers both.

Every serious multi-agent deployment hits the same wall: a human has to create an API key, copy it, and paste it into a config — once per agent, forever. That does not scale to fifty agents, and it does not survive auto-scaling.

There are two ways out: let the agent register itself, or authorize once and issue programmatically — a human creates a single Management API Key, and your orchestrator uses it to mint a dedicated key for every agent, each with its own spend cap.

Option A: the agent registers itself

The registration endpoint lives on the website host, bazaarlink.ai (not the api. gateway host). It needs no sign-in and no Authorization header:

curl -X POST https://bazaarlink.ai/api/v1/agents/register \
  -H "Content-Type: application/json" \
  -d '{"name": "research-agent"}'

Body fields: name (required), description, referral_code. The 201 response carries api_key, credits, a seven-day claim_token (so a human can claim the account later), upgrade_url, free_model: "auto:free" and base_url. The api_key is shown once — store it immediately.

import httpx
from langchain_openai import ChatOpenAI

def self_register(name: str) -> ChatOpenAI:
    r = httpx.post("https://bazaarlink.ai/api/v1/agents/register", json={"name": name}, timeout=30)
    r.raise_for_status()
    data = r.json()
    return ChatOpenAI(
        model=data["free_model"],  # auto:free
        openai_api_key=data["api_key"],
        openai_api_base=data["base_url"],  # https://api.bazaarlink.ai/v1
    )

worker = self_register("worker-1")

A self-registered account is unpaid: it uses the existing free-model mechanism (auto:free) under the ordinary rate and daily limits. There is no separate agent free tier, and the free web-search allowance needs a verified email, so it is not included. Signups per IP or cloud provider are capped; past the cap you get HTTP 429 — retry after the Retry-After header.

Need paid models? Register with an OKX payment (x402)

POST https://bazaarlink.ai/api/v1/agents/register/x402 with name and amountUsd registers and funds the account in one flow. The first request returns HTTP 402 with the payment terms (network eip155:196, asset USD-T0, payTo); the agent signs and resends with an X-PAYMENT header. Payment is USD₮0 on X Layer, settled through OKX's x402 facilitator, and gasless for the payer (no OKB needed; sign with OKX Wallet or any EVM wallet).

A platform top-up fee applies, so the credited balance is lower than the amount paid; the response lists paidUsd, creditedUsd and serviceFeeUsd separately. Later top-ups go to POST https://bazaarlink.ai/api/x402/topup with the account's API key.

Option B: the two-step model

  1. A human, once. Sign in, go to /keys, create a Management API Key. It exists to manage other keys; it is not used to call models.
  2. Your code, forever after. Call POST /v1/keys with that management key to issue a scoped key per agent.

A normal sk-bl- key cannot call this endpoint — only a management key can. That separation is deliberate.

curl https://api.bazaarlink.ai/v1/keys \
  -H "Authorization: Bearer $BAZAARLINK_MANAGEMENT_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "research-agent",
    "limit": 30,
    "limit_reset": "monthly",
    "expires_at": "2027-01-01T00:00:00Z"
  }'

The key field in the response is the only time the plaintext key is ever visible. Hand it to the agent or store it in your secret manager immediately.

LangChain

import os

import httpx
from langchain_openai import ChatOpenAI

MGMT_KEY = os.environ["BAZAARLINK_MANAGEMENT_KEY"]
BASE = "https://api.bazaarlink.ai/v1"

def provision_key(name: str, monthly_usd: float) -> str:
    r = httpx.post(
        f"{BASE}/keys",
        headers={"Authorization": f"Bearer {MGMT_KEY}"},
        json={"name": name, "limit": monthly_usd, "limit_reset": "monthly"},
        timeout=30,
    )
    r.raise_for_status()
    return r.json()["key"]

def build_agent(name: str, monthly_usd: float = 10.0) -> ChatOpenAI:
    return ChatOpenAI(
        model="auto:free",
        openai_api_key=provision_key(name, monthly_usd),
        openai_api_base=BASE,
    )

worker_1 = build_agent("worker-1")
worker_2 = build_agent("worker-2")

CrewAI

from crewai import Agent
from langchain_openai import ChatOpenAI

researcher = Agent(
    role="Senior Researcher",
    llm=ChatOpenAI(
        model="anthropic/claude-sonnet-4.6",
        openai_api_key=provision_key("crew-researcher", 25.0),
        openai_api_base="https://api.bazaarlink.ai/v1",
    ),
)

AutoGen

AutoGen's OAI_CONFIG_LIST pattern takes a provisioned key the same way:

config_list = [{
    "model": "openai/gpt-4o",
    "api_key": provision_key("autogen-planner", 20.0),
    "base_url": "https://api.bazaarlink.ai/v1",
}]

What you can lock down at issue time

FieldEffect
limit + limit_resetSpend cap in USD and its reset period: daily, weekly, or monthly
expires_atISO timestamp, must be in the future — ideal for ephemeral CI keys
organizationId / teamId / orgMemberIdAttribute the key to an org, team, or member for cost allocation
keyTypeDefaults to standard; use management only to mint another management key

When a key hits its cap, its requests return HTTP 402. Other agents keep running. That is the whole point: one runaway agent cannot drain the account.

When to provision per agent

ScenarioProvision per agent?Why
Multi-agent crew with distinct rolesYesPer-role spend tracking and independent caps
Auto-scaling worker poolYesEach instance is attributable and separately revocable
Ephemeral CI jobsYes, with expires_atNothing long-lived sits in the pipeline
Single script on your laptopNoOne key from the dashboard is simpler

Proving the pipeline first

A freshly issued key can call auto:free immediately, which routes to whichever free model is currently available (ordinary rate and daily limits apply). You can prove the whole pipeline works before adding credits, then switch to paid models without changing code.

Lifecycle management

The same management endpoints cover the rest of the lifecycle: GET /v1/keys to list, PATCH to adjust a cap, DELETE to revoke when an agent retires. Usage per key appears in Logs under the name you gave it at creation.

FAQ

Can an AI agent get its own API key automatically? Yes. The agent can call POST https://bazaarlink.ai/api/v1/agents/register itself and gets an unpaid account on auto:free; or a human creates one Management API Key and your orchestrator mints a capped key per agent with POST /v1/keys. Use the OKX x402 registration endpoint if the agent needs paid models from the start.

Which frameworks does this work with? Any framework that speaks the OpenAI API: LangChain, CrewAI, AutoGen, LangGraph, LlamaIndex, Semantic Kernel, or your own client. Set base_url to https://api.bazaarlink.ai/v1 and pass the provisioned key.

Where should the management key live? Only in the orchestrator or CI secret store. Never ship it to individual agents — they should only ever hold their own capped standard key.

Is a provisioned key free to use? Creating a key costs nothing. Calls to auto:free carry no per-token charge; paid models draw on your balance (up to the cap you set on that key, when you provision with a Management API Key).

Try BazaarLink now

TWD billing · Taiwan invoices · leading AI models · OpenAI-compatible API

Sign up / Log in for freeEnterprise inquiries
Related posts
Claude Code · Claude Code update · changelog · mods · permission rules
Claude Code 2.1.289: 27 Changes, Permission-Rule Fixes and Mods Stability
Claude Code · Claude Code mods · plugins · TypeScript · AI coding tools
Claude Code Mods: Customize Behavior and UI with TypeScript
web search API · AI agent · LLM · Hermes Agent
Hermes Agent Web Search: Use a BazaarLink Model with :online
Support
Support
Hi! How can we help you?
Send a message and we'll get back to you soon.