Fully-typed and auto-generated TypeScript client for the Torn City v2 API. Supports Node.js and browsers
npm install torn-client




A TypeScript-first, auto-generated client for the Torn City v2 API
This client provides full type safety, built-in rate limiting and automatic multi-key balancing to simplify interactions with the Torn API
> ⚠️ Warning
>
> The Torn v2 API is under active development and changes frequently
> This client is also a work in progress, use with caution
>
> Some multi-selection endpoints like /user - are not yet fully tested and may behave unexpectedly
- Fully Typed: Provides strong type safety and autocompletion for API methods and responses
- Cross-Environment: Works seamlessly in both Node.js and browser environments
- Zero Runtime Dependencies: No external dependencies, ensuring a lightweight footprint and easy integration
- Multi-Key Management: Automatically balances requests across multiple API keys using round-robin or random strategies
- Built-in Rate Limiting: Avoids hitting the API limit by auto-delaying requests
- Robust Pagination: Simple .next() and .prev() methods are always available on paginated API responses
- Auto-Generated: The client is generated from the official OpenAPI specification, ensuring it stays up-to-date with API changes
``shUsing npm
npm install torn-client
`torn-client
You can also use directly in a browser without any build tools by importing it from a CDN like unpkg
`html`
`ts
import { TornAPI } from 'torn-client';
// Initialize the client with your API keys
const client = new TornAPI({
apiKeys: ['YOUR_API_KEY'],
comment: 'MyTornApp',
});
// Example: Fetch a user's profile using a context method
async function getUserProfile() {
try {
const user = await client.user.withId(1).profile();
console.log(user.name, user.level, user.gender);
} catch (error) {
console.error('Failed to fetch user profile:', error);
}
}
getUserProfile();
`
The client separates general calls from ID-based ones
Global Call
`ts`
// Fetches the Hall of Fame for factions, sorted by respect
const factionHof = await client.torn.factionhof({ cat: 'respect' });
Context-Specific Call
`ts
// All subsequent calls are now in the context of user ID 1
const userContext = client.user.withId(1);
// Fetch multiple details for the same user without repeating the ID
const profile = await userContext.profile();
const personalStats = await userContext.personalstats({ cat: 'all' });
const properties = await userContext.properties();
`Documentation
Full API client reference is available at the Torn Client Docs
For information about Torn API endpoints and parameters, see the official Torn API v2 documentation
Contributions, issues, and feature requests are welcome!
Feel free to open an issue or submit a pull request on GitHub
Please read contributing guide first
Got a question? Open an issue with the "question" label
You can also contact me in Torn: Neon or on Discord: neon0404`