jatevo-x402-sdk
v1.3.0
Published
Simple axios interceptor for Jatevo x402 LLM API - Works in terminals, VSCode, and Node.js
Maintainers
Readme
jatevo-x402-sdk
Simple axios interceptor for Jatevo x402 LLM API - Works in terminals, VSCode, and Node.js
🆕 Version 1.3.0 - GLM 4.6 Support
Added support for the latest GLM 4.6 model with enhanced reasoning capabilities. Simple axios interceptor pattern that works perfectly in terminals, VSCode, and any Node.js environment!
Features
- 🎯 Simple Integration - Just wrap your axios instance with our interceptor
- 🖥️ Terminal/CLI Ready - Works perfectly in Node.js, terminals, and VSCode
- 🚀 No API Keys Required - Your wallet address is your authentication
- 💰 Pay-Per-Use - Only pay for what you actually use ($0.01 per request)
- ⚡ Instant Settlement - Payments handled through PayAI facilitator
- 🌐 Dual Network Support - Choose between Base or Solana for payments
- 🤖 Multiple Models - Access to Qwen, GLM, Kimi, DeepSeek, and GPT-OSS
- 🔒 Secure - EIP-3009 compliant (Base) and SPL token transfers (Solana)
- 📦 TypeScript Support - Full type definitions included
- 🔑 Private Key Support - Works with private keys for terminal/CLI usage
Installation
npm install jatevo-x402-sdk
# or
yarn add jatevo-x402-sdk
# or
pnpm add jatevo-x402-sdkQuick Start
const { withPaymentInterceptor } = require('jatevo-x402-sdk');
const axios = require('axios');
// Your EVM private key (keep this secure!)
const PRIVATE_KEY = process.env.PRIVATE_KEY;
// Create axios client with payment interceptor
const client = withPaymentInterceptor(axios.create(), PRIVATE_KEY);
// Make API requests - payments are handled automatically
const response = await client.post('https://api.jatevo.ai/chat/completions/qwen', {
messages: [
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: 'Explain async/await in JavaScript' }
],
temperature: 0.7,
max_tokens: 200
});
console.log(response.data.choices[0].message.content);How It Works
- Request Sent: Your request is sent to the Jatevo API
- 402 Response: If payment is required, the API returns a 402 status
- Auto-Payment: SDK creates a payment header using your private key
- Retry Request: Request is automatically retried with payment
- Get Response: You receive the API response seamlessly
Configuration Options
The SDK uses a simple pattern with minimal configuration:
const { withPaymentInterceptor } = require('jatevo-x402-sdk');
const axios = require('axios');
// Basic usage with private key
const client = withPaymentInterceptor(
axios.create(), // Your axios instance
privateKey // Your EVM private key (for Base) or Solana private key
);Available Models
| Model ID | Name | Description | Price |
|----------|------|-------------|-------|
| qwen | Qwen 3 Coder 480B | Advanced code generation and analysis | $0.01 |
| glm-4.6 | GLM 4.6 | Latest GLM model with enhanced reasoning | $0.01 |
| glm-4.5 | GLM 4.5 | Advanced reasoning and problem-solving | $0.01 |
| kimi | Kimi K2 | Long context understanding | $0.01 |
| deepseek-r1-0528 | DeepSeek R1 0528 | Latest reasoning model | $0.01 |
| deepseek-v3.1 | DeepSeek V3.1 | Efficient chat model | $0.01 |
| gpt-oss | GPT-OSS | OpenAI's efficient model | $0.01 |
Example Usage
Basic Chat Completion
const { withPaymentInterceptor } = require('jatevo-x402-sdk');
const axios = require('axios');
async function chat() {
const client = withPaymentInterceptor(
axios.create(),
process.env.PRIVATE_KEY
);
try {
const response = await client.post(
'https://api.jatevo.ai/chat/completions/qwen',
{
messages: [
{ role: 'user', content: 'What is the capital of France?' }
],
temperature: 0.7,
max_tokens: 100
}
);
console.log(response.data.choices[0].message.content);
} catch (error) {
console.error('Error:', error.message);
}
}
chat();Streaming Responses
const response = await client.post(
'https://api.jatevo.ai/chat/completions/kimi',
{
messages: [...],
stream: true
},
{
responseType: 'stream'
}
);
response.data.on('data', chunk => {
console.log(chunk.toString());
});Using Different Models
// Qwen model
await client.post('https://api.jatevo.ai/chat/completions/qwen', {...});
// GLM models
await client.post('https://api.jatevo.ai/chat/completions/glm-4.6', {...}); // Latest
await client.post('https://api.jatevo.ai/chat/completions/glm-4.5', {...});
// Kimi K2 model
await client.post('https://api.jatevo.ai/chat/completions/kimi', {...});
// DeepSeek models
await client.post('https://api.jatevo.ai/chat/completions/deepseek-r1-0528', {...});
await client.post('https://api.jatevo.ai/chat/completions/deepseek-v3.1', {...});
// GPT-OSS model
await client.post('https://api.jatevo.ai/chat/completions/gpt-oss', {...});Error Handling
The SDK provides clear error messages:
try {
const response = await client.post(...);
} catch (error) {
if (error.response?.status === 402) {
console.error('Payment required but failed:', error.message);
} else if (error.response?.status === 429) {
console.error('Rate limit exceeded');
} else {
console.error('API error:', error.message);
}
}Network Support
The SDK automatically handles payments on both Base and Solana networks:
- Base Network: Fast settlement (~200ms) using USDC on Base L2
- Solana Network: Reliable settlement (~400ms) using USDC on Solana
Simply provide your private key and the SDK handles the rest - no network configuration needed!
Migration from v1.x
If you were using v1.0.x or v1.1.x, update your code:
Old Pattern (v1.0.x/v1.1.x)
// Complex client initialization
const client = new X402Client({
baseUrl: 'https://api.jatevo.ai',
privateKey: PRIVATE_KEY,
network: 'base'
});
const response = await client.chat.completions(...);New Pattern (v1.2.0) - Simpler!
// Simple axios interceptor
const client = withPaymentInterceptor(axios.create(), PRIVATE_KEY);
const response = await client.post('https://api.jatevo.ai/chat/completions/qwen', {...});Benefits of v1.2.0
- Simpler API: Just one function -
withPaymentInterceptor - No Browser Dependencies: Works in any Node.js environment
- Smaller Bundle: Reduced from ~50KB to ~5KB
- Better Error Handling: Clear error messages
- PayAI Integration: Automatic retry on payment failures
TypeScript Types
import type {
X402Config,
LLMMessage,
LLMRequest,
LLMResponse,
ModelType,
ModelInfo,
PaymentRequirements,
EVMPaymentData,
SolanaPaymentData
} from 'jatevo-x402-sdk';Support
- Documentation: https://jatevo.ai/x402/documentation
- Website: https://jatevo.ai
- Issues: https://github.com/jatevo/x402-sdk/issues
License
MIT © Jatevo
