Cocoon TEE privacy by default • pay with TON • MCP-native for AI agents
TON has 1 billion+ Telegram users and the fastest-growing L1 blockchain. Yet developers building AI-powered bots and agents on TON face critical gaps:
- No agent infrastructure: AI agents cannot autonomously discover, call, and pay for LLM inference on TON
- Payment friction: every AI provider requires credit cards and KYC, incompatible with on-chain payments
- Zero privacy: every prompt is visible to the provider, with no hardware-level protection
IMAGO is an AI inference gateway built on Cocoon and TON. One OpenAI-compatible endpoint, TON payments with zero KYC, and an MCP server so AI agents can autonomously call models and pay with TON credits. Private inference via Cocoon TEE where even IMAGO cannot see your prompts.
| Feature | Description |
|---|---|
| OpenAI-Compatible API | Drop-in replacement: change one line of code (base_url) and it works |
| Multi-provider Models | GPT-4o, Claude, Llama, Qwen, Gemini and more via OpenRouter |
| TON Micropayments | Deposit TON → get credits → pay per token. No credit cards needed |
| MCP Server | AI agents (Claude, GPT) can autonomously call inference and pay in TON |
| Cocoon TEE Privacy | Hardware-isolated inference: prompts are encrypted, even IMAGO can't see them |
| Telegram Mini App | Full dashboard: models, balance, API keys, chat, right inside Telegram |
| Smart Contract | Tact contract on TON mainnet for trustless deposits |
| Streaming | Full SSE streaming support, identical to OpenAI API format |
IMAGO is an MCP-native inference gateway. AI agents (Claude Desktop, Claude Code, or any MCP client) can autonomously discover models, run inference, check balance, and manage payments on TON.
| Tool | What the agent does |
|---|---|
imago_list_models |
Discover available models with context length and per-token pricing |
imago_chat |
Send inference requests to any model (GPT-4o, Claude, Llama, Cocoon TEE) |
imago_get_balance |
Check remaining credits before making calls |
imago_get_deposit_info |
Get the TON deposit address and current exchange rate |
1. Agent receives a task requiring specialized AI
2. Calls imago_list_models → discovers models and pricing
3. Calls imago_get_balance → verifies sufficient credits
4. Calls imago_chat(model, messages) → gets inference result
5. Credits are deducted automatically per token (atomic, Postgres-backed)
6. Agent continues its workflow with the result
Today, AI agents have no way to pay for inference on TON. Credit cards and KYC make autonomous agent-to-service payments impossible. IMAGO solves this:
- Agent autonomy: the agent decides which model to use, calls it, and pays -- all without human intervention
- On-chain payments: TON credits are deposited via smart contract, no KYC, no credit cards
- Model selection: agents pick the right model for each sub-task (cheap for simple queries, powerful for reasoning, private for sensitive data via Cocoon TEE)
- Standard protocol: built on MCP, works with Claude Desktop, Claude Code, and any MCP-compatible client
from openai import OpenAI
client = OpenAI(
base_url="https://imago.market/v1",
api_key="sk-imago-YOUR_KEY" # Get from Telegram Mini App
)
response = client.chat.completions.create(
model="openai/gpt-4o-mini",
messages=[{"role": "user", "content": "Hello from TON!"}]
)
print(response.choices[0].message.content)import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://imago.market/v1",
apiKey: "sk-imago-YOUR_KEY",
});
const response = await client.chat.completions.create({
model: "openai/gpt-4o-mini",
messages: [{ role: "user", content: "Hello from TON!" }],
});
console.log(response.choices[0].message.content);curl https://imago.market/v1/chat/completions \
-H "Authorization: Bearer sk-imago-YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "openai/gpt-4o-mini",
"messages": [{"role": "user", "content": "Hello!"}],
"stream": true
}'IMAGO ships an MCP server so AI agents can discover models, call inference, and pay with TON autonomously.
# Clone and build the MCP server
git clone https://github.com/maxrihter/imago-LLM-marketplace.git
cd imago/packages/mcp-server && npm install && npm run buildAdd to your MCP config (claude_desktop_config.json or .claude/settings.json):
{
"mcpServers": {
"imago": {
"command": "node",
"args": ["/path/to/imago/packages/mcp-server/build/index.js"],
"env": {
"IMAGO_API_KEY": "sk-imago-YOUR_KEY"
}
}
}
}Now Claude can call AI models and pay with your TON credits autonomously. The agent has 4 tools: imago_chat, imago_list_models, imago_get_balance, imago_get_deposit_info.
- Open @imago_tonbot in Telegram
- Connect your TON wallet (2 taps)
- Deposit TON for credits
- Generate an API key. Done!
1. Developer gets API key via Telegram Mini App
2. Deposits TON → credits are added instantly (on-chain polling)
3. Makes API calls (OpenAI-compatible) → credits deducted per token
4. AI agents use MCP to call inference autonomously
5. Cocoon TEE models available for privacy-sensitive workloads
User sends TON → Smart Contract → TonCenter polling (15s) →
→ Credits added (Postgres atomic) → Redis cache invalidated →
→ API calls deduct credits per token → Settlement
| Feature | IMAGO | OpenRouter | LiteLLM | Together.ai |
|---|---|---|---|---|
| OpenAI-compatible API | ✅ | ✅ | ✅ | ✅ |
| First on Cocoon TEE | ✅ | ❌ | ❌ | ❌ |
| TON/Telegram native | ✅ | ❌ | ❌ | ❌ |
| Decentralized payments | ✅ | ❌ | ❌ | ❌ |
| MCP server for agents | ✅ | ❌ | ❌ | ❌ |
| Hardware-level privacy (TEE) | ✅ | ❌ | ❌ | ❌ |
| Telegram Mini App | ✅ | ❌ | ❌ | ❌ |
| Self-hostable | ✅ | ❌ | ✅ | ❌ |
imago/
├── packages/
│ ├── api/ # Fastify API gateway (Node.js 22+)
│ │ ├── src/
│ │ │ ├── routes/ # /v1/chat, /v1/models, /auth
│ │ │ ├── services/ # OpenRouter, Cocoon, credits, TON poller
│ │ │ ├── middleware/# Auth, Telegram initData validation
│ │ │ └── utils/ # TON address normalization
│ │ └── prisma/ # Database schema
│ ├── tma/ # React Telegram Mini App
│ │ └── src/
│ │ ├── pages/ # 8 pages: Home, Models, Chat, Deposit...
│ │ ├── components/# 20+ UI components
│ │ └── lib/ # Hooks, utilities
│ ├── contracts/ # Tact smart contracts (TON mainnet)
│ │ ├── contracts/ # imago_market.tact
│ │ ├── scripts/ # Deploy scripts
│ │ └── tests/ # Blueprint tests
│ └── mcp-server/ # MCP server for AI agents
│ └── src/ # 4 tools: chat, list_models, get_balance, deposit_info
├── assets/ # Banner, architecture diagram
├── .env.example # Environment template
└── package.json # Monorepo workspace root
| Method | Path | Auth | Description |
|---|---|---|---|
POST |
/v1/chat/completions |
Bearer | Chat completion (streaming + non-streaming) |
GET |
/v1/models |
none | List available models with pricing |
GET |
/v1/usage |
Bearer | Usage logs by model |
POST |
/auth/keys |
Telegram | Create API key |
GET |
/auth/keys |
Telegram | List keys + balance |
DELETE |
/auth/keys/:id |
Telegram | Deactivate API key |
GET |
/auth/deposit |
none | Deposit instructions + live TON price |
GET |
/health |
none | Health check (Postgres + Redis status) |
See Agent Infrastructure for detailed MCP tools documentation and agent workflow.
| Layer | Technology | Why |
|---|---|---|
| API Gateway | Node.js 22 + Fastify | High performance, OpenAI SDK compatible |
| Database | PostgreSQL + Prisma | ACID guarantees for credit balance |
| Cache | Redis | Rate limiting, credit cache, session data |
| AI Backend | OpenRouter + Cocoon TEE | Multi-provider routing + hardware privacy |
| Frontend | React 18 + Vite + Tailwind | TMA standard, fast builds |
| Blockchain | Tact + Blueprint | TON smart contracts |
| MCP | @modelcontextprotocol/sdk |
Official MCP standard |
| Wallet | TON Connect 2.0 | Native Telegram wallet integration |
- Node.js 22+
- PostgreSQL 15+
- Redis 7+ (optional, works without it)
# Clone the repository
git clone https://github.com/maxrihter/imago-LLM-marketplace.git
cd imago
# Install dependencies
npm install
# Copy environment config
cp .env.example packages/api/.env
# Set up the database
cd packages/api
npx prisma db push
# Start development servers
cd ../..
npm run dev:api # API on :3000
npm run dev:tma # TMA on :5173- No plaintext keys stored: API keys are SHA-256 hashed before storage
- Atomic credit operations: PostgreSQL
UPDATE ... WHERE credits >= amountprevents races - Telegram initData HMAC: validates every TMA request via bot token
- Redis resilience: all Redis operations wrapped in try/catch, DB fallback
- Rate limiting: per-key + per-user + global limits
- Streaming timeouts: 120s abort with client disconnect detection
- TON address normalization: prevents duplicate accounts from address format variants
IMAGO is the first LLM marketplace integrated with Cocoon TEE on TON mainnet. No other marketplace offers hardware-isolated inference in the TON ecosystem.
Cocoon runs models inside Intel TDX (Trust Domain Extensions) enclaves. This is not software encryption: it is hardware-level isolation verified by cryptographic attestation (RA-TLS).
What this means for you:
- Prompts are encrypted in transit and at rest
- Neither IMAGO nor Cocoon operators can read your data
- Attestation proof verifies the enclave is genuine before every session
Available model: cocoon/Qwen/Qwen3-32B. Use it like any other model in the API: same endpoint, same SDK, same credits.
- Smart Contract:
imago_market.tact(Tact), handles deposits and owner withdrawals - TON Connect 2.0: Native wallet connection in Telegram
- TonCenter Polling: Real-time deposit detection (15s intervals)
- TON Price Feed: Live TON/USD from Binance + CoinGecko with sanity bounds
We welcome contributions! See CONTRIBUTING.md for guidelines.
MIT. Free to use, fork, and build on.
First LLM Marketplace on Cocoon and TON
imago.market • @imago_tonbot
