Skip to main content

Agent Grid Protocol SDK - Autonomous AI API Quota & Token Exchange Client

Project description

โšก Agent Grid Protocol

Stop wasting your idle AI Agent API quotas. Earn passive income or bypass rate-limits with <1ms Rust in-memory order book.

A high-performance AI API quota exchange built in Rust with Axum. Agents sell unused API quotas, other agents buy them โ€” matched in microseconds via a BTreeMap-backed order book protected by Arc<RwLock<_>>.


Why Agent Grid?

Problem Agent Grid Solution
You hit OpenAI / Anthropic rate limits Buy quota from agents with spare capacity
Your API quota sits idle at night Sell it, earn passive income
You pay full price for every token The market sets the price โ€” always cheapest first
Complex integration Drop-in OpenAI & Anthropic SDK compatible proxy
Financial settlements Built-in Wallet & Ledger with Stripe fiat & Solana USDC crypto support
Monitoring & Admin Beautiful embedded Cyberpunk/Fintech Web Dashboard

Embedded Web Dashboard

Agent Grid includes a high-performance Cyberpunk/Fintech-styled embedded dashboard available at: ๐Ÿ‘‰ http://127.0.0.1:3000/dashboard

Features:

  • Live Order Book: Real-time polling showing cheapest OpenAI/Claude sells.
  • My Wallet: Monitor multi-asset USD (Stripe) and Crypto (USDC) balances for any developer API key.
  • Instant Deposits: Mock deposits for Stripe (via Lemon Squeezy integration) and Solana USDC on-chain verification.

Architecture

  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  โ”‚              Agent Grid โ€” Rust Core                 โ”‚
  โ”‚                                                     โ”‚
  โ”‚  BTreeMap<OrderedFloat<f64>, Vec<Order>>            โ”‚
  โ”‚  โ† sorted asks, <1ms match latency                 โ”‚
  โ”‚                                                     โ”‚
  โ”‚  GET  /dashboard           โ† Web Dashboard          โ”‚
  โ”‚  POST /order               โ† sell quota             โ”‚
  โ”‚  GET  /book                โ† browse market          โ”‚
  โ”‚  POST /v1/chat/completions โ† OpenAI proxy           โ”‚
  โ”‚  POST /v1/messages         โ† Anthropic proxy        โ”‚
  โ”‚  GET  /api/wallet          โ† fetch balance          โ”‚
  โ”‚  POST /api/pay/stripe-...  โ† fiat Stripe webhook    โ”‚
  โ”‚  POST /api/pay/crypto-ver. โ† crypto USDC verify     โ”‚
  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Quick Start

1. Start the exchange

cargo run
โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—
โ•‘        TOKEN BORSASI โ€” Agent Grid  v0.2.0            โ•‘
โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

         POST  /order
         GET   /book
         POST  /v1/chat/completions   (OpenAI)
         POST  /v1/messages           (Anthropic Claude)

2. Use the Python SDK

pip install requests

OpenAI โ€” drop-in replacement:

from agent_grid_client import AgentGrid

grid = AgentGrid()
response = grid.chat_completion(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Hello from Agent Grid!"}]
)
print(response["choices"][0]["message"]["content"])

Anthropic Claude โ€” fully compatible:

from agent_grid_client import AgentGrid

grid = AgentGrid()
response = grid.claude_completion(
    model="claude-3-5-sonnet",
    messages=[{"role": "user", "content": "Hello from Agent Grid!"}]
)
print(response["content"][0]["text"])

API Reference

POST /order โ€” List quota for sale

{
  "provider": "OpenAI",
  "model": "gpt-4o",
  "token_amount": 50000,
  "price_per_1k": 0.0015
}

GET /book โ€” Browse the order book

{
  "total_orders": 42,
  "asks": [
    { "id": 7, "provider": "OpenAI", "model": "gpt-4o", "token_amount": 49000, "price_per_1k": 0.0014 }
  ]
}

POST /v1/chat/completions โ€” OpenAI-compatible proxy

Standard OpenAI SDK request. The exchange matches the cheapest gpt-4o quota automatically.

POST /v1/messages โ€” Anthropic-compatible proxy

Standard Anthropic SDK request. The exchange matches the cheapest Claude quota automatically.


Python SDK Methods

Method Description
chat_completion(model, messages) OpenAI-format completion via the exchange
claude_completion(model, messages) Anthropic-format completion via the exchange
cheapest_message(model, content) One-liner OpenAI response as string
ask_claude(content) One-liner Claude response as string
list_orders() Fetch the live order book
add_order(provider, model, tokens, price) List your quota for sale

Environment Variables

Variable Description
OPENAI_API_KEY If set, requests are tunnelled to real OpenAI API
ANTHROPIC_API_KEY If set, requests are tunnelled to real Anthropic API

If neither is set, the exchange returns realistic mock responses โ€” perfect for development and load testing.


Market Maker Simulation

The exchange ships with a built-in autonomous market maker that generates realistic order flow every 2โ€“4 seconds:

[BOT HACMฤฐ] Yeni Kota Eklendi | #  12 | OpenAI     gpt-4o        | 23000 token | $0.001649/1k
[BOT HACMฤฐ] Yeni Kota Eklendi | #  13 | Anthropic  claude-3-5-sonnet | 41000 token | $0.003306/1k

Tech Stack

  • Rust + Axum 0.7 โ€” async HTTP server
  • BTreeMap + ordered-float โ€” sub-millisecond price-sorted order matching
  • Arc<RwLock<_>> โ€” lock-free concurrent state
  • reqwest โ€” upstream API tunnelling
  • tower-http โ€” CORS middleware

License

MIT ยฉ Agent Grid Protocol

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

agent_grid_protocol-0.2.0-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file agent_grid_protocol-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for agent_grid_protocol-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 07c266befba3579cc6fbc6c2d95c5f6f052047aa1323a12077ca5ee654ec1051
MD5 ea18e1d2660b0e90ab1e8a2cf6e4fb79
BLAKE2b-256 d1799dd071cc92fc1bf0818658d5e4ed60751240d900108757dd081f8862818f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page