Skip to content

majcheradam/steam-typescript

Repository files navigation

steam-typescript

A type-safe TypeScript SDK for the Steam Web API with automatic API key management, built with OpenAPI and Zod validation.

Features

  • đź”’ Type-safe - Full TypeScript support with generated types
  • âś… Validated - Request and response validation with Zod schemas
  • 🔑 Auto API Key - Automatically reads STEAM_API_KEY from .env
  • 🚀 Modern - ESM-first, built on native fetch
  • 📦 Zero config - Works out of the box

Installation

npm install steam-typescript zod
# or
yarn add steam-typescript zod
# or
bun add steam-typescript zod

Quick Start

1. Get your Steam API Key

Get your API key from Steam Web API Key

2. Set up environment variable

Create a .env file in your project root:

STEAM_API_KEY=your_api_key_here

3. Use the SDK

import { createSteamClient, getISteamUserGetPlayerSummariesV0002 } from 'steam-typescript';

// Create client - automatically uses STEAM_API_KEY from .env
const client = createSteamClient();

// Fetch player summaries
const result = await getISteamUserGetPlayerSummariesV0002({
  client,
  query: {
    steamids: '76561197960435530'
  }
});

if (result.data) {
  console.log(result.data);
}

Usage

Automatic API Key (Recommended)

The SDK automatically reads STEAM_API_KEY from your .env file:

import { createSteamClient, getISteamUserGetPlayerSummariesV0002 } from 'steam-typescript';

const client = createSteamClient();

const result = await getISteamUserGetPlayerSummariesV0002({
  client,
  query: {
    steamids: '76561197960435530'
  }
});

Manual API Key

You can also set the API key programmatically:

import { createSteamClient, setApiKey } from 'steam-typescript';

// Set API key before creating client
setApiKey('YOUR_STEAM_API_KEY');

const client = createSteamClient();

Using the default client

For simple use cases, you can use the SDK functions without creating a client:

import { getISteamNewsGetNewsForAppV0002 } from 'steam-typescript';
import { setApiKey } from 'steam-typescript';

// Set your API key
setApiKey('YOUR_STEAM_API_KEY');

// Use SDK functions directly
const news = await getISteamNewsGetNewsForAppV0002({
  query: {
    appid: 440, // Team Fortress 2
    count: 5
  }
});

Available Endpoints

News

  • getISteamNewsGetNewsForAppV0002 - Get latest news for a game

Users

  • getISteamUserGetPlayerSummariesV0002 - Get public Steam profile data
  • getISteamUserGetFriendListV0001 - Get friend list for a Steam user

Achievements & Stats

  • getISteamUserStatsGetGlobalAchievementPercentagesForAppV0002 - Get global achievement percentages
  • getISteamUserStatsGetPlayerAchievementsV0001 - Get achievements for a user in a game
  • getISteamUserStatsGetUserStatsForGameV0002 - Get user stats + achievements

Player Service

  • getIPlayerServiceGetOwnedGamesV0001 - Get owned games (public profiles only)
  • getIPlayerServiceGetRecentlyPlayedGamesV0001 - Get recently played games

Examples

Get Player Profile

import { createSteamClient, getISteamUserGetPlayerSummariesV0002 } from 'steam-typescript';

const client = createSteamClient();

const result = await getISteamUserGetPlayerSummariesV0002({
  client,
  query: {
    steamids: '76561197960435530'
  }
});

if (result.data) {
  const player = result.data.response?.players?.[0];
  console.log(`Player: ${player?.personaname}`);
}

Get Owned Games

import { createSteamClient, getIPlayerServiceGetOwnedGamesV0001 } from 'steam-typescript';

const client = createSteamClient();

const result = await getIPlayerServiceGetOwnedGamesV0001({
  client,
  query: {
    steamid: '76561197960435530',
    include_appinfo: true
  }
});

if (result.data) {
  const games = result.data.response?.games ?? [];
  console.log(`Found ${games.length} games`);
}

Get Game News

import { createSteamClient, getISteamNewsGetNewsForAppV0002 } from 'steam-typescript';

const client = createSteamClient();

const result = await getISteamNewsGetNewsForAppV0002({
  client,
  query: {
    appid: 440, // Team Fortress 2
    count: 5,
    maxlength: 300
  }
});

if (result.data) {
  const news = result.data.appnews?.newsitems ?? [];
  for (const item of news) {
    console.log(`${item.title}: ${item.url}`);
  }
}

Error Handling

The SDK returns both data and error, following the throwOnError pattern:

const result = await getISteamUserGetPlayerSummariesV0002({
  client,
  query: {
    steamids: 'invalid'
  }
});

if (result.error) {
  console.error('API Error:', result.error);
} else {
  console.log('Success:', result.data);
}

To throw errors instead:

const result = await getISteamUserGetPlayerSummariesV0002({
  client,
  throwOnError: true, // Will throw on error
  query: {
    steamids: '76561197960435530'
  }
});

// result.data is guaranteed to exist here
console.log(result.data);

TypeScript Support

All API responses are fully typed:

import type { GetISteamUserGetPlayerSummariesV0002Responses } from 'steam-typescript';

const result = await getISteamUserGetPlayerSummariesV0002({
  client,
  query: {
    steamids: '76561197960435530'
  }
});

// TypeScript knows the structure
const players = result.data?.response?.players;

Environment Variables

Variable Required Description
STEAM_API_KEY Yes Your Steam Web API key from steamcommunity.com/dev/apikey

License

MIT

Contributing

Contributions are welcome! This SDK is generated from an OpenAPI specification. To modify or extend:

  1. Update steam-web-api-openapi.yaml
  2. Run bun openapi-ts to regenerate the SDK
  3. Test your changes

Links

About

A type-safe TypeScript SDK for the Steam Web API with automatic API key management, built with OpenAPI and Zod validation.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published