Main class
Provides access to all API sections
const client = new TornAPI({ apiKeys: ["YOUR_API_KEY1", "YOUR_API_KEY2"], comment: "my-app", rateLimitMode: "autoDelay", verbose: true,});const userProfile = await client.user.withId(12345).get(); Copy
const client = new TornAPI({ apiKeys: ["YOUR_API_KEY1", "YOUR_API_KEY2"], comment: "my-app", rateLimitMode: "autoDelay", verbose: true,});const userProfile = await client.user.withId(12345).get();
The TornAPI constructor accepts the following options:
TornAPI
apiKeys
string[]
rateLimitMode
'autoDelay' │ 'throwOnLimit' │ 'ignore'
'autoDelay'
apiKeyBalancing
'roundRobin' │ 'random'
'roundRobin'
comment
string
undefined
headers
Record<string, string>
{}
verbose
boolean
false
true
The client is organized by API categories:
client.user
client.faction
client.market
client.property
client.racing
client.forum
client.key
client.torn
Endpoints that return lists are paginated
The response object is a special PaginatedResponse class that always includes .next() and .prev() methods to easily fetch adjacent pages
PaginatedResponse
.next()
.prev()
If a page does not exist, these methods return null
null
autoDelay
throwOnLimit
TornRateLimitError
ignore
Creates an instance of the TornAPI client
Configuration options for the client
Readonly
Returns real-time rate limit information for each API key and values contain usage details
Main class
Provides access to all API sections
Example
Configuration
The
TornAPI
constructor accepts the following options:apiKeys
string[]
rateLimitMode
'autoDelay' │ 'throwOnLimit' │ 'ignore'
'autoDelay'
apiKeyBalancing
'roundRobin' │ 'random'
'roundRobin'
comment
string
undefined
comment
query parameter for your requestsheaders
Record<string, string>
{}
verbose
boolean
false
true
, logs all outgoing requests, responses, and rate limit eventsCore Concepts
API Endpoints
The client is organized by API categories:
client.user
client.faction
client.market
client.property
client.racing
client.forum
client.key
client.torn
Pagination
Endpoints that return lists are paginated
The response object is a special
PaginatedResponse
class that always includes.next()
and.prev()
methods to easily fetch adjacent pagesIf a page does not exist, these methods return
null
Rate Limiting
autoDelay
(Default): Automatically queues requests to ensure you do not exceed the 100 req/min limitthrowOnLimit
: Throws aTornRateLimitError
if a request would exceed the limitignore
: Disables rate limiting. Not recommended unless you have your own external limiter