Quick Start
Get up and running with AgentFish in 5 minutes.
Server SDK
1. Initialize the Client
import { AgentFish } from '@agentfish/sdk';
const agent = new AgentFish({
apiKey: process.env.AGENTFISH_API_KEY!,
walletId: process.env.AGENTFISH_WALLET_ID!,
});
2. Make Requests with Automatic Payments
// AgentFish handles 402 Payment Required automatically
const response = await agent.fetch('https://api.example.com/ai-endpoint', {
method: 'POST',
body: JSON.stringify({ prompt: 'Hello AI' }),
});
const data = await response.json();
3. Check Your Balance
const balance = await agent.getBalance();
console.log(`Balance: $${balance.balance} USDC`);
console.log(`Daily remaining: $${balance.dailyRemaining} USDC`);
React SDK
1. Wrap Your App
import { AgentFishProvider } from '@agentfish/react';
import '@agentfish/react/styles.css';
function App() {
return (
<AgentFishProvider
config={{
app: {
appId: 'your-agentfish-app-id',
},
}}
>
<YourApp />
</AgentFishProvider>
);
}
2. Add Authentication
import { SignIn, WalletButton, useAuth } from '@agentfish/react';
function YourApp() {
const { isAuthenticated } = useAuth();
return (
<div>
{isAuthenticated ? (
<WalletButton />
) : (
<SignIn providers={['email', 'passkey', 'wallet']} />
)}
</div>
);
}
3. Make Payments
import { useAgentFish } from '@agentfish/react';
function PaymentExample() {
const { fetch, balance } = useAgentFish();
const handleRequest = async () => {
// Automatic x402 payment handling
const response = await fetch('https://ai-api.com/chat', {
method: 'POST',
body: JSON.stringify({ message: 'Hello' }),
maxPayment: 1.00, // Cap at $1 USDC
});
const data = await response.json();
console.log(data);
};
return (
<div>
<p>Balance: ${balance} USDC</p>
<button onClick={handleRequest}>Make Request</button>
</div>
);
}
Next Steps
- SDK Reference - Full API documentation
- React SDK - Components and hooks
- Error Handling - Handle payment errors gracefully