BazaarLinkBazaarLink
登入
← 所有文章
發布時間 2026-05-01 · · 作者:BazaarLink · AI Agents · API Key Management · LangChain · CrewAI · AutoGen · Multi-Agent

AI Agents That Get Their Own API Key — Self-Registration and Provisioning for LangChain, CrewAI & AutoGen

BazaarLink agent self-registration is open: POST https://bazaarlink.ai/api/v1/agents/register returns an API key, with an OKX x402 paid option. Or provision capped keys with a Management API Key. LangChain, CrewAI and AutoGen examples.

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).

立即體驗 BazaarLink

台幣計費・統一發票・主流 AI 模型・OpenAI 相容 API

免費註冊 / 登入企業採購洽詢
相關文章
Claude Code · Claude Code 更新 · changelog · mods · 權限規則
Claude Code 2.1.289 更新整理:27 項變更、權限規則修補與 mods 穩定性
Claude Code · Claude Code mods · plugin · TypeScript · AI 編程工具
Claude Code 開放 Mods:用 TypeScript 改行為、改介面、換功能
聯網搜尋 · AI agent · LLM · Hermes Agent
Hermes Agent 聯網搜尋:用 BazaarLink 模型加 :online
客服
客服
您好!有什麼可以協助?
請留下訊息,我們會盡快回覆。