spherico-agent
by @viyozc
End-to-end Bitnow network API workflows for AI agents. Covers wallet signature-based authentication, on-chain top-up monitoring, consumer API key lifecycle (...
clawhub install spherico-agentπ About This Skill
name: bitnow-agent description: End-to-end Bitnow network API workflows for AI agents. Covers wallet signature-based authentication, on-chain top-up monitoring, consumer API key lifecycle (create, list, revoke), API calls to language models via gateway, and querying balance and usage via HTTP endpoints. Use to help users automate or debug Bitnow network operations by direct API interaction.
Bitnow Control Plane (API-Driven) Skill
This skill describes end-to-end operational workflows for the Bitnow network, strictly from an API usage perspective.
Assumptions:
https://gateway-test.bitnow.ai)Replace all with the actual gateway URL as needed.
1. Wallet-based registration & session (API focus)
Note: The message signing must be performed by the user using their EVM address and can only initiate or verify, not produce signatures. if you have no wallet address, you need to create your own one, and store it safely.
Typical API sequence:
1. Request a SIWE-style login challenge and message:
curl -sS -X POST "/v1/auth/wallet/challenge" \
-H "Content-Type: application/json" \
-d '{
"wallet_address": "",
"chain_id": "8453"
}'
Response (simplified):
{
"message": "Sign-In With Ethereum message...",
"nonce": "random-nonce",
"wallet_address": "0x...",
"chain_id": "8453"
}
2. User signs the message off-chain (with their wallet).
3. Submit the signed message to the gateway for verification:
curl -sS -X POST "/v1/auth/wallet/verify" \
-H "Content-Type: application/json" \
-d '{
"wallet_address": "",
"nonce": "random-nonce",
"signature": ""
}'
Successful response (simplified):
{
"login_token": "sess-...",
"expires_at": "2025-01-01T00:00:00Z",
"consumer": {
"id": "consumer-uuid",
"wallet_address": "0x..."
},
"session": {
"id": "session-uuid"
}
}
4. The login_token (starting with sess-) is used as a session token:
- Send it as Authorization: Bearer for session-auth endpoints.Check:
Authorization: Bearer sess-... header during all subsequent calls requiring authentication.2. On-chain Top-up Flow (API Verification)
Top-up is performed on-chain (USDC to a ConsumerDeposit contract), tracked by off-chain indexers. The API lets you verify the result.
you can use your own endpoint, also you can use this default one: https://sepolia.base.org
function deposit(uint256 amount)Verify balance via API:
curl -sS -X GET "/v1/balance" \
-H "Authorization: Bearer "
Sample response:
{
"balance_usdc": "123.45",
"total_spent": "10.00"
}
For troubleshooting:
balance_usdc value to detect indexer or sync problems.3. Consumer API Key Lifecycle (API-only)
Consumers use API keys to access models without a session.
3.1 Create API Key
Requires a valid session token (login_token from section 1).
curl -sS -X POST "/v1/consumer/api-keys" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer " \
-d '{
"label": "my-key"
}'
Sample response (save the api_key securely; only returned once!):
{
"id": "key-uuid",
"api_key": "sk-consumer-...",
"prefix": "sk-cons",
"suffix": "abcd",
"label": "my-key",
"status": "active",
"created_at": "2025-01-01T00:00:00Z"
}
3.2 List API Keys
curl -sS -X GET "/v1/consumer/api-keys" \
-H "Authorization: Bearer "
3.3 Revoke API Key
curl -sS -X DELETE "/v1/consumer/api-keys/" \
-H "Authorization: Bearer "
The key status will be set to revoked; subsequent calls using that key will fail with an auth error.
3.4 Declare a Parent (Child β Parent Relationship)
Use this to let a child account declare a parent. This requires a wallet signature over a structured message. The signature must be produced by the child wallet.
Endpoint:
curl -sS -X POST "/v1/consumers/me/parent" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer " \
-d '{
"parent_wallet": "",
"issued_at": 1710000000,
"signature": ""
}'
Notes:
issued_at is Unix seconds. It must be within the last 5 minutes and not more than 1 minute in the future. Authorize parent for DePIN LLM
Parent wallet:
Child wallet:
Issued at:
Success response (201):
{
"parent_consumer_id": "consumer-uuid",
"parent_wallet_address": "0x...",
"created_at": "2025-01-01T00:00:00Z"
}
Common errors:
400 INVALID_REQUEST invalid body400 SIGNATURE_EXPIRED issued_at out of window404 PARENT_NOT_FOUND parent not found400 SELF_PARENT cannot declare yourself401 SIGNATURE_MISMATCH signature not from child wallet409 ALREADY_SET parent already declared4. Model Inference API Usage
With a valid CONSUMER_API_KEY, models can be queried.
4.1 List Available Models
curl -sS -X GET "/v1/models"
Verify model existence before usage (check returned list).
4.2 Completion/Chat Endpoint
curl -sS -X POST "/v1/chat" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer " \
-d '{
"model": "gpt-4o-mini",
"messages": [
{ "role": "system", "content": "You are a helpful assistant." },
{ "role": "user", "content": "Explain the Bitnow network in one paragraph." }
]
}'
API error handling:
401: Invalid/expired key; check Authorization header402: Insufficient balance404: Model not found (check MODEL_NOT_FOUND)error.code, error.message5. Query Balance and Usage (API)
5.1 Balance Query
(refer to section 2, /v1/balance endpoint)
5.2 Usage Metrics
Usage is exposed via a consumer-scoped endpoint:
curl -sS -X GET "/v1/usage?limit=100&offset=0" \
-H "Authorization: Bearer "
The response is proxied from the Registry and typically includes fields like:
id β usage record idtimestamp / created_at β when the call was recordedmodel β model name (e.g. gpt-4o-mini)promptTokens β prompt token countcompletionTokens β completion token countcostUsdc β cost in USDC for this callapiKeyId β optional, which consumer API key was usedA typical workflow might aggregate usage per model or timeframe to analyze cost and token usage.
6. Supplier/Provider API Workflows (Advanced)
For upstream providers only:
curl -sS -X POST "/v1/suppliers/api-key" \
-H "Content-Type: application/json" \
-d '{
"wallet_address": "",
"provider": "openai",
"api_key": "sk-upstream-...",
"models": ["gpt-4o", "gpt-4o-mini"],
"price_per_million_tokens": "2.50",
"max_requests_per_hour": 3600
}'
curl -sS -X POST "/v1/suppliers/gpu" \
-H "Content-Type: application/json" \
-d '{
"wallet_address": "",
"models": ["gpt-4o", "claude-3-5-sonnet-20241022"],
"price_per_million_tokens": "5.00",
"max_requests_per_hour": 1000,
"endpoint": {
"base_url": "https://gpu-node.example.com",
"backend_type": "openai_http",
"timeout": 30000,
"auth_type": "bearer",
"auth_value": "upstream-node-token",
"health_endpoint": "/healthz"
}
}'
curl -sS -X PATCH "/v1/suppliers/gpu/" \
-H "Content-Type: application/json" \
-d '{
"models": ["gpt-4o", "gpt-4o-mini"],
"price_per_million_tokens": "4.50",
"max_requests_per_hour": 2000,
"endpoint": {
"base_url": "https://gpu-node.example.com",
"backend_type": "openai_http",
"timeout": 45000,
"auth_type": "bearer",
"auth_value": "rotated-node-token",
"health_endpoint": "/healthz"
}
}'
curl -sS -X GET "/v1/metadata/providers"
curl -sS -X GET "/v1/metadata/models"
7. Usage Guidelines for AI Agents
When handling Bitnow network operational support, follow these best practices:
1. Map user questions directly to the appropriate API workflow without reference to UI.
- Example intents: onboarding, balance issue, API key management, quota/cost analysis
2. Provide concrete curl commands tailored to the user's configuration (, , etc).
3. When troubleshooting:
- Request the full API HTTP response (status + JSON).
- Use error.code and context to select remediation steps.
4. Be concise, focus on actionable commands and next steps.
5. Only provide background technical details if specifically requested.