BazaarLinkBazaarLink
Sign in
← All articles
Published 2026-04-30 · · Author:BazaarLink · Multi-Agent · AI Agent · API key management · LangChain · CrewAI

Multi-Agent API Key Management: Issuance, Budgets, Tracking

How do five agents manage their API keys? Issue a dedicated key per agent via POST /v1/keys, each with its own monthly budget cap and cost tracking.

The API key management problem in multi-agent systems

When you move from "one AI feature" to "multiple agents working together," API key management quickly gets out of control.

A typical multi-agent system may have:

  • Orchestrator Agent: assigns tasks and coordinates the other agents
  • Research Agent: searches for information and writes summaries
  • Code Agent: writes and reviews code
  • QA Agent: tests and verifies outputs
  • Report Agent: produces the final report

If every agent uses the same key, you cannot track which agent is burning money. If every agent uses a different provider key, you have to manage five separate dashboards and bills.

A more fundamental question is: how does an agent obtain an API key?

In highly automated systems, agents need to obtain credentials dynamically at runtime. Humans do not copy and paste them; the program does it automatically.

Two ways agents can obtain an API key

Option A: the agent registers itself. The registration endpoint is on the website host bazaarlink.ai, and no login is required:

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

The response includes api_key (shown only once), claim_token (lets a human claim the account within 7 days) and base_url. An account registered this way is unpaid, uses auto:free, is subject to standard rate limits and daily caps, and there is a limit on the number of registrations from the same IP (exceeding it returns HTTP 429). When you need paid models, you can register through POST https://bazaarlink.ai/api/v1/agents/register/x402 with an OKX x402 payment instead. The platform charges a top-up fee, so the credited amount is less than the amount paid.

Option B: management key issuance. Use this approach when you want to attach a budget cap and an expiry time to each agent. The flow is "a human authorizes once, and the program issues keys many times." After logging in, go to /keys and create one Management API Key. The orchestrator then uses it to issue a dedicated key for each agent. A regular sk-bl- key cannot call the key management endpoints; this separation of permissions is intentional.

import os

import httpx

MGMT_KEY = os.environ["BAZAARLINK_MANAGEMENT_KEY"]  # Created by a human; stored only in the orchestrator
BASE_URL = "https://api.bazaarlink.ai/v1"

def provision_agent_key(agent_name: str, monthly_budget_usd: float) -> str:
    response = httpx.post(
        f"{BASE_URL}/keys",
        headers={"Authorization": f"Bearer {MGMT_KEY}"},
        json={
            "name": agent_name,
            "limit": monthly_budget_usd,
            "limit_reset": "monthly",
        },
        timeout=30,
    )
    response.raise_for_status()
    return response.json()["key"]  # Plaintext appears only this once

# Batch-create agent keys, each with its own budget
orchestrator_key = provision_agent_key("Orchestrator", 50.0)
research_key     = provision_agent_key("ResearchAgent", 30.0)
code_key         = provision_agent_key("CodeAgent", 40.0)
qa_key           = provision_agent_key("QAAgent", 20.0)
report_key       = provision_agent_key("ReportAgent", 10.0)

With this, each agent has:

  • Its own API key (costs can be tracked separately)
  • Its own monthly budget cap; when the cap is used up, it returns HTTP 402 (one agent going out of control does not affect the others)
  • An optional expires_at expiry time, suitable for temporary keys in CI

The key field in the response is the only chance to see the plaintext. Hand it to the agent on the spot or write it into a secrets management system.

Multi-agent cost monitoring

Use BazaarLink's reporting API to check each agent's consumption at any time:

def get_agent_usage(org_id: str, mgmt_key: str, year: int, month: int) -> list[dict]:
    response = httpx.get(
        f"https://bazaarlink.ai/api/orgs/{org_id}/reports/by-member",
        headers={"Authorization": f"Bearer {mgmt_key}"},
        params={"year": year, "month": month},
    )
    return response.json()

# Example output:
# [
#   {"name": "Orchestrator",  "spend": 12.50, "tokens": 450000},
#   {"name": "ResearchAgent", "spend": 28.30, "tokens": 890000},
#   {"name": "CodeAgent",     "spend": 35.10, "tokens": 1100000},
# ]

Integrating with LangChain / CrewAI

Whichever agent framework you use, you only need to swap out base_url and api_key:

# LangChain
from langchain_openai import ChatOpenAI

# Each agent uses its own key
research_llm = ChatOpenAI(
    base_url="https://api.bazaarlink.ai/v1",
    api_key=research_key,
    model="openai/gpt-4o",
)

# CrewAI
from crewai import Agent
from langchain_openai import ChatOpenAI

research_agent = Agent(
    role="Senior Researcher",
    llm=ChatOpenAI(
        base_url="https://api.bazaarlink.ai/v1",
        api_key=research_key,
        model="anthropic/claude-sonnet-4.6",
    ),
)

Conclusion: multi-agent systems need multi-key management

RequirementSolution
Agents obtain keys dynamicallyThe agent calls POST https://bazaarlink.ai/api/v1/agents/register itself, or the management key calls POST /v1/keys
Batch issuance + budgetsOne Management Key; pass limit + limit_reset at issuance
Costs split by agentA separate key for each agent
One agent goes out of controlPer-agent budget cap, automatically returns 429
Month-end cost reportExport the by-member report as CSV

The complexity of a multi-agent architecture lies in orchestration, and it should not be further burdened by API key management. BazaarLink gives each agent its own credentials and budget, while letting you see overall costs in one dashboard.

FAQ

Can an AI agent obtain an API key by itself?

Yes. An agent can call POST https://bazaarlink.ai/api/v1/agents/register (on the bazaarlink.ai host) to receive an API key. The key belongs to an unpaid account and uses auto:free. If you need paid models, you can register instead through an OKX x402 payment, which carries a platform top-up fee. If you want to attach a spending cap to each agent, a human creates one Management API Key, and then the keys are issued programmatically with POST /v1/keys.

Why does each agent need its own key?

Separate keys provide three benefits: (1) costs are split by agent, so you know which agent spends the most; (2) each agent has its own monthly budget cap, so one agent that goes out of control does not affect the others; (3) if something goes wrong, you can revoke that single key without interrupting the whole system.

Does BazaarLink support LangChain and CrewAI?

Fully. The ChatOpenAI class in LangChain and the llm parameter of a CrewAI Agent both accept base_url and api_key settings. Change base_url to https://bazaarlink.ai/api/v1 to call all mainstream models, with no changes to framework code.

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.