SweatHost
SDK Reference

Authentication

Learn how to authenticate with the SweatHost API using API keys

Authentication

The SweatHost SDK uses API keys for authentication. You can create and manage API keys from your dashboard.

Creating an API Key

  1. Log in to your SweatHost Dashboard
  2. Navigate to API Keys in the sidebar
  3. Click Create API Key
  4. Give your key a name and select the appropriate scopes
  5. Copy the API key (it will only be shown once!)

Initializing the SDK

import { SweatHostClient } from '@sweathost/sdk';

const client = new SweatHostClient({
  apiKey: 'your-api-key-here',
  baseUrl: 'https://api.sweathost.com', // optional, defaults to production
});

Configuration Options

OptionTypeRequiredDefaultDescription
apiKeystringYes-Your API key from the dashboard
baseUrlstringNohttps://api.sweathost.comAPI base URL
timeoutnumberNo30000Request timeout in milliseconds

Example: Complete Setup

import { SweatHostClient } from '@sweathost/sdk';

// Initialize the client
const client = new SweatHostClient({
  apiKey: process.env.SWEATHOST_API_KEY!,
  baseUrl: process.env.SWEATHOST_API_URL || 'https://api.sweathost.com',
  timeout: 60000, // 60 seconds
});

// Test the connection
async function testConnection() {
  try {
    const servers = await client.gameServers.list({ page: 1, pageSize: 10 });
    console.log(`✓ Connected! Found ${servers.total} servers`);
  } catch (error) {
    console.error('✗ Connection failed:', error.message);
  }
}

testConnection();

API Key Scopes

API keys can have different scopes to limit their permissions:

ScopeDescription
servers:readRead game server information
servers:writeCreate, update, and delete game servers
servers:controlStart, stop, and restart servers
matches:readRead match data and statistics
matches:writeCreate and update matches
regions:readRead region information

Security Best Practices

Never expose your API key in client-side code or public repositories!

  1. Store keys securely: Use environment variables or a secrets manager
  2. Use minimal scopes: Only grant the permissions your application needs
  3. Rotate keys regularly: Create new keys and delete old ones periodically
  4. Monitor usage: Check your API key usage in the dashboard
  5. Use different keys: Use separate keys for development, staging, and production

Error Handling

The SDK will throw an ApiClientError if authentication fails:

import { SweatHostClient, ApiClientError } from '@sweathost/sdk';

const client = new SweatHostClient({
  apiKey: 'invalid-key',
});

try {
  await client.gameServers.list();
} catch (error) {
  if (error instanceof ApiClientError) {
    if (error.statusCode === 401) {
      console.error('Invalid API key');
    } else if (error.statusCode === 403) {
      console.error('Insufficient permissions');
    }
  }
}

Next Steps

On this page