API Keys
Create API keys for programmatic access to the Ethos API from bots, scripts, and integrations.
Quick start
import { privateKeyToAccount } from "viem/accounts";
import { createSiweMessage } from "viem/siwe";
const API = "https://api.ethos.network/api/v2";
const CLIENT = "[email protected]"; // identifies your app
const account = privateKeyToAccount("0xYOUR_PRIVATE_KEY");
// --- 1. Create API key ---
const message = createSiweMessage({
domain: "api.ethos.network",
address: account.address,
statement: "Create Ethos API key",
uri: "https://api.ethos.network",
version: "1",
chainId: 8453, // Base
nonce: crypto.randomUUID().replaceAll("-", ""),
issuedAt: new Date(),
expirationTime: new Date(Date.now() + 10 * 60 * 1000), // must be within 10 min
});
const signature = await account.signMessage({ message });
const keyResp = await fetch(`${API}/api-keys`, {
method: "POST",
headers: { "Content-Type": "application/json", "X-Ethos-Client": CLIENT },
body: JSON.stringify({
address: account.address,
message,
signature,
name: "my-bot",
}),
});
if (!keyResp.ok) throw new Error(`Create key failed: ${await keyResp.text()}`);
const { id: keyId, token } = await keyResp.json();
console.log("Key created:", keyId);
// --- 2. Send XP tip ---
const tipResp = await fetch(`${API}/xp/tip`, {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-Ethos-Api-Key": token,
"X-Ethos-Client": CLIENT,
},
body: JSON.stringify({
receiverUserkey: "profileId:1",
amount: 5,
message: "5 XP, 10 lines of code — developers.ethos.network",
}),
});
if (!tipResp.ok) throw new Error(`Tip failed: ${await tipResp.text()}`);
const tip = await tipResp.json();
console.log(`Tip #${tip.tipId} sent. Balance: ${tip.senderNewBalance} XP`);
// --- 3. Revoke key ---
const revokeResp = await fetch(`${API}/api-keys/${keyId}`, {
method: "DELETE",
headers: { "X-Ethos-Api-Key": token, "X-Ethos-Client": CLIENT },
});
if (!revokeResp.ok) throw new Error(`Revoke failed: ${await revokeResp.text()}`);
console.log("Key revoked");Creating a key
SIWE message requirements
Field
Value
Notes
Request: POST /api/v2/api-keys
POST /api/v2/api-keysField
Type
Required
Description
Response
Authenticating requests
Revoking a key
Reference
Key lifecycle
Property
Value
Endpoints
Method
Path
Auth
Error codes
HTTP
Code
Meaning
Last updated