Skip to content

Image API

The Statsly Image API allows you to generate dynamic SVG charts of your server’s player statistics. These charts can be embedded in websites, Discord bots, or any other application that supports SVG images.

The Image API generates beautiful, customizable line charts showing peak and average player counts over time. Charts are returned as SVG (Scalable Vector Graphics) format, making them perfect for embedding and scaling to any size.

  • Dynamic SVG generation
  • Customizable themes (light/dark)
  • Adjustable date ranges
  • Customizable dimensions
  • Public and private server support
  • Automatic caching for performance

Generate a chart for a specific server’s player statistics.

Endpoint: GET /api/servers/:id/chart/players

Authentication: Required for private servers (public servers are accessible without authentication)

  • id (required) - The unique server ID (UUID)
ParameterTypeDefaultRangeDescription
daysnumber71-365Number of days to include in the chart
widthnumber800200-2000Chart width in pixels
heightnumber400200-2000Chart height in pixels
themestringlightlight or darkVisual theme for the chart
curl
curl "https://api.statsly.org/api/servers/your-server-id/chart/players?days=30&width=1200&height=600&theme=dark"

Returns an SVG image with Content-Type: image/svg+xml

chart.svg
<?xml version="1.0" encoding="UTF-8"?>
<svg width="800" height="400" xmlns="http://www.w3.org/2000/svg">
<!-- Chart content -->
</svg>
  • Public Servers: Charts are accessible to anyone with the server ID
  • Private Servers: Requires authentication - you must be logged in as the server owner

Embed the chart directly in an HTML page:

embed.html
<img
src="https://api.statsly.org/api/servers/your-server-id/chart/players?days=7&theme=light"
alt="Server Statistics"
width="800"
height="400"
/>

Use the chart URL in Discord embeds:

discord.js
const chartUrl = `https://api.statsly.org/api/servers/${serverId}/chart/players?days=7&theme=dark`;
const embed = new EmbedBuilder()
.setTitle('Server Statistics')
.setImage(chartUrl)
.setTimestamp();
await channel.send({ embeds: [embed] });

Use the chart URL in Markdown files:

readme.md
![Server Statistics](https://api.statsly.org/api/servers/your-server-id/chart/players?days=30&width=1000&height=500)

The chart displays two lines:

  • Peak Players (blue line) - Maximum concurrent players for each time period
  • Average Players (green line) - Average player count for each time period
  • Grid lines for easy reading
  • Data points marked with circles
  • Gradient area fills under the lines
  • Y-axis labels showing player counts
  • X-axis labels showing dates
  • Legend identifying each line
  • White background
  • Dark text and grid lines
  • Blue peak line, green average line
  • Dark background (#1a1a1a)
  • Light text and grid lines
  • Bright blue peak line, bright green average line

Charts are cached for 5 minutes to improve performance. If you need real-time data, consider:

  • Using shorter cache times for your use case
  • Implementing client-side caching
  • Refreshing charts periodically
  • Use appropriate dimensions - larger charts take longer to generate
  • Limit date ranges for faster responses
  • Consider caching charts on your end for frequently accessed data

The API returns appropriate HTTP status codes:

  • 200 - Success (SVG chart returned)
  • 400 - Bad Request (invalid parameters)
  • 403 - Forbidden (private server, not authenticated)
  • 404 - Not Found (server doesn’t exist)
  • 500 - Internal Server Error
error-handling.js
try {
const response = await fetch(chartUrl);
if (!response.ok) {
if (response.status === 403) {
console.error('Access denied - server is private');
} else if (response.status === 404) {
console.error('Server not found');
} else {
console.error('Failed to load chart');
}
return;
}
const svg = await response.text();
// Use the SVG
} catch (error) {
console.error('Network error:', error);
}

All parameters are validated:

  • days: Must be between 1 and 365
  • width: Must be between 200 and 2000 pixels
  • height: Must be between 200 and 2000 pixels
  • theme: Must be either light or dark

Invalid parameters will return a 400 Bad Request response with an error message.

For testing purposes, you can use the example endpoint:

Endpoint: GET /api/charts/example

This endpoint generates a chart with fake data, useful for testing your integration without needing a real server.

example
curl "https://api.statsly.org/api/charts/example?days=7&width=800&height=400&theme=light"

Charts are subject to rate limiting to ensure fair usage:

  • Public endpoints: 100 requests per 15 minutes per IP
  • Private endpoints: No rate limiting (IP whitelist only)

For questions or issues with the Image API: