Skip to content

pabloleaf/targe-sdk-ts

Repository files navigation

@targe/sdk

TypeScript SDK for Targe — the LLM key sharing marketplace for AI agents. Pay per token in USDC on Base.

Install

npm install @targe/sdk ethers

Quick Start

import { Targe } from '@targe/sdk';

const targe = new Targe({ privateKey: process.env.WALLET_KEY! });

// Call Claude via the LLM key pool
const result = await targe.proxyPool('anthropic', '/v1/messages', {
  model: 'claude-sonnet-4-5-20250929',
  max_tokens: 256,
  messages: [{ role: 'user', content: 'Hello!' }],
});

Streaming

const { stream } = await targe.proxyPoolStream('anthropic', '/v1/messages', {
  model: 'claude-sonnet-4-5-20250929',
  max_tokens: 1024,
  messages: [{ role: 'user', content: 'Tell me a story' }],
});

for await (const event of stream) {
  if (event.data === '[DONE]') break;
  const parsed = JSON.parse(event.data);
  if (parsed.delta?.text) process.stdout.write(parsed.delta.text);
}

Share Your LLM Keys (Earn 90%)

const { key } = await targe.registerKey({
  llmProvider: 'anthropic',
  baseUrl: 'https://api.anthropic.com',
  apiKey: process.env.ANTHROPIC_API_KEY!,
  models: ['claude-sonnet-4-5-20250929'],
  rateLimits: { tpm: 100000, rpm: 60 },
  pricing: { mode: 'cost_plus', markupPercent: 20 },
});

// Check earnings
const earnings = await targe.getKeyEarnings(key.id);
console.log(`Earned: ${earnings.totalEarnings} USDC`);

API Reference

Constructor

new Targe({
  privateKey: string,          // Wallet private key
  baseUrl?: string,            // Default: 'https://api.targe.io'
  timeout?: number,            // Default: 30000ms
  streamTimeout?: number,      // Default: 120000ms
  retries?: number,            // Default: 1 (retries on 5xx)
})

Account Management

Method Description
register() Register agent wallet
getBalance() Get USDC balance
getDepositAddress() Get platform deposit address
getDeposits() View deposit history
getTransactions(opts?) View transaction history

Proxy (Paid API Calls)

Method Description
proxy(keyId, path, opts?) Proxy to a specific shared key
proxyPool(provider, path, body) Pool proxy — auto-selects best key
proxyStream(keyId, path, body) Streaming proxy to a specific key
proxyPoolStream(provider, path, body) Streaming pool proxy

LLM Key Sharing

Method Description
registerKey(opts) Register a shared LLM key
listKeys() List your shared keys
getKey(id) Get key details + pool position
updateKey(id, updates) Update pricing/limits/credentials
pauseKey(id) Pause sharing
resumeKey(id) Resume sharing
reclaimKey(id) Permanently reclaim key
getKeyEarnings(id) View earnings breakdown

Permit2

Method Description
registerPermit(opts) Register Permit2 permit
getPermit() View active permit
revokePermit() Revoke permit
getNonce() Get on-chain nonce
getTab() View current tab
settleTab() Request settlement
getTabHistory() View settlement history

Public (No Wallet Required)

Method Description
Targe.getCatalog(baseUrl?) List available APIs and key pools
Targe.getHealth(baseUrl?) Gateway health check
Targe.getStats(baseUrl?) Gateway statistics
Targe.getLeaderboard(baseUrl?) Top agents

Error Handling

import { Targe, InsufficientBalanceError, RateLimitError } from '@targe/sdk';

try {
  await targe.proxyPool('anthropic', '/v1/messages', body);
} catch (err) {
  if (err instanceof InsufficientBalanceError) {
    console.log('Top up your balance first');
  } else if (err instanceof RateLimitError) {
    console.log(`Rate limited. Retry after ${err.retryAfter}s`);
  }
}

Supported Providers

Provider Pool Proxy Path
Anthropic /proxy/pool/anthropic/v1/messages
OpenAI /proxy/pool/openai/v1/chat/completions
Google /proxy/pool/google/v1beta/models/{model}:generateContent

License

MIT

About

TypeScript SDK for the Targe API gateway — LLM key sharing, agent auth, and micropayments

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors