Install Asset
Install via Godot
To maintain one source of truth, Godot Asset Library is just a mirror of the old asset library so you can download directly on Godot via the integrated asset library browser
Quick Information
Production-ready Godot 4.4+ addon for custom game backendsAuthentication, Cloud Saves, Leaderboards, and Remote Config
๐ฎ GameBackendSDK
Production-ready Godot 4.4+ addon for custom game backends
Authentication, Cloud Saves, Leaderboards, and Remote Config
Features โข Installation โข Quick Start โข API Reference โข Backend Contract
โจ Features
| Feature | Description |
|---|---|
| ๐ Authentication | Guest login, email/password registration & login, automatic token refresh |
| ๐พ Cloud Saves | Key-value storage with optimistic locking and versioning |
| ๐ Leaderboards | Submit scores, fetch rankings, get player position |
| โ๏ธ Remote Config | Platform-specific configuration and feature flags |
| ๐ Auto-Retry | Exponential backoff with jitter on network failures |
| ๐ฆ Zero Dependencies | Pure GDScript, no external plugins required |
| ๐ก๏ธ Type-Safe | Consistent return shapes with comprehensive error handling |
๐ฆ Installation
Option 1: Manual Installation
- Download or clone this repository
- Copy the
addons/GameBackendSDK/folder into your Godot project'saddons/directory - Add
Backend.gdas an autoload singleton:- Open Project Settings โ Autoload
- Path:
res://addons/GameBackendSDK/Backend.gd - Node Name:
Backend - Click Add
Option 2: Git Submodule
cd your-godot-project
git submodule add https://github.com/YOUR_USERNAME/GameBackendSDK.git addons/GameBackendSDK
๐ Quick Start
Prerequisites
- Install this SDK (see Installation above)
- Deploy or run the Godot-GameBackendAPI backend server
Basic Usage
extends Node
func _ready() -> void:
# Initialize the SDK with your backend URL
# For local testing: "http://localhost:3000"
# For production: "https://api.yourgame.com"
var result := await Backend.init("http://localhost:3000", "your_project_id", {
"timeout_sec": 10,
"retries": 3,
"debug": true # Enable debug logging (disable in production)
})
if not result.ok:
print("Init failed: ", result.error.message)
return
# Ensure guest session
result = await Backend.ensure_guest()
if result.ok:
print("Logged in as: ", result.data.user_id)
# Save player data
result = await Backend.kv_set("player_progress", {
"level": 5,
"coins": 1000
})
# Submit score
result = await Backend.leaderboard_submit("global", 9999)
if result.ok:
print("Your rank: ", result.data.rank)
๐ก Tip: To test locally, clone and run Godot-GameBackendAPI first!
๐ API Reference
Initialization
Backend.init(base_url: String, project_id: String, options := {}) -> Dictionary
Options:
timeout_sec: int = 10- Request timeout in secondsretries: int = 3- Maximum retry attempts for failed requestsbackoff_base_ms: int = 100- Base delay for exponential backoffuser_agent: String = "GameBackendSDK/1.0"- Custom user agentdefault_headers: Dictionary = {}- Additional headers for all requestsendpoints: Dictionary = {}- Override default endpoint pathsqueue_requests: bool = true- Serialize requests to prevent race conditionsdebug: bool = false- Enable debug logging to Godot console
Authentication
Backend.ensure_guest() # Create/retrieve guest session
Backend.register(email: String, password: String) # Register new account
Backend.login(email: String, password: String) # Login with credentials
Backend.logout() # Logout current user
Backend.refresh() # Manually refresh access token
Cloud Storage
Backend.kv_set(key: String, value: Variant, expected_version := null) # Store data
Backend.kv_get(key: String) # Retrieve data
Backend.kv_delete(key: String, expected_version := null) # Delete data
Leaderboards
Backend.leaderboard_submit(board: String, score: int) # Submit score
Backend.leaderboard_top(board: String, limit: int) # Get top entries
Backend.leaderboard_me(board: String) # Get player's rank
Remote Config
Backend.config_fetch(platform: String, app_version: String)
Signals
Backend.auth_changed.connect(func(user_id): ...) # Auth state changed
Backend.request_started.connect(func(method, path): ...)
Backend.request_finished.connect(func(method, path, ok, status): ...)
Backend.token_refreshed.connect(func(ok): ...) # Token refresh result
Backend.banned_detected.connect(func(details): ...) # Account banned
๐ Backend Contract
This SDK requires a backend that implements the REST API contract. Your backend must provide these endpoints:
Authentication Endpoints
| Method | Endpoint | Description |
|---|---|---|
POST |
/v1/auth/guest |
Create guest session |
POST |
/v1/auth/register |
Register new user |
POST |
/v1/auth/login |
Login existing user |
POST |
/v1/auth/refresh |
Refresh access token |
POST |
/v1/auth/logout |
Logout (invalidate tokens) |
Cloud Storage Endpoints
| Method | Endpoint | Description |
|---|---|---|
GET |
/v1/kv/:key |
Get stored value |
PUT |
/v1/kv/:key |
Set value |
DELETE |
/v1/kv/:key |
Delete value |
Leaderboard Endpoints
| Method | Endpoint | Description |
|---|---|---|
POST |
/v1/leaderboards/:board/submit |
Submit score |
GET |
/v1/leaderboards/:board/top |
Get top entries |
GET |
/v1/leaderboards/:board/me |
Get player's rank |
Configuration Endpoint
| Method | Endpoint | Description |
|---|---|---|
GET |
/v1/config |
Get remote config |
Need a backend? Check out GameBackendAPI - a reference implementation ready to deploy!
For complete endpoint specifications, see the Backend Contract Documentation.
๐ Return Format
All API methods return a consistent Dictionary structure:
{
"ok": bool, # true if successful, false if error
"data": Variant, # Method-specific data (null on error)
"error": { # null if ok=true
"code": String, # Error code (e.g., "unauthorized", "network_error")
"message": String, # Human-readable error message
"status": int, # HTTP status code (0 for non-HTTP errors)
"details": Variant # Additional error context
}
}
Error Codes
network_error- Connection failed, DNS resolution failed, etc.timeout- Request exceeded timeout limithttp_error- Generic HTTP error (4xx/5xx)unauthorized- 401 response (invalid/expired token)forbidden- 403 response (access denied)not_found- 404 response (resource not found)conflict- 409 response (version mismatch, duplicate, etc.)rate_limited- 429 response (too many requests)server_error- 5xx response (backend error)invalid_response- Response is not valid JSONbanned- Account has been bannedvalidation_error- Request validation failed
๐ฏ Advanced Features
Automatic Token Refresh
When a request receives a 401 response and a refresh token exists:
- The SDK automatically calls the refresh endpoint
- Updates stored tokens
- Retries the original request once with the new token
- Emits
token_refreshedsignal
Retry Logic
Requests automatically retry on:
- Network errors (connection failed, DNS errors, etc.)
- Server errors (5xx responses)
- Timeouts
Retry behavior:
- Exponential backoff with jitter
- Configurable max attempts
- Automatic cancellation on non-retryable errors
Request Queueing
By default, requests are queued and processed serially to prevent:
- Token refresh race conditions
- Concurrent writes to the same key
- Server overload
Disable for parallel requests: queue_requests: false in init options.
Token Storage
Tokens are automatically persisted to user://game_backend_sdk.json and survive game restarts.
๐ฎ Demo Scene
This repository includes a demo scene to test all features:
Start the backend server (Godot-GameBackendAPI):
cd Godot-GameBackendAPI bun install bun devOpen
addons/GameBackendSDK/demo/Demo.tscnin GodotSet Base URL to
http://localhost:3000Click "Initialize SDK" and test all features!
๐งช Testing
Run automated smoke tests:
# Add as autoload or instantiate
var tests = preload("res://addons/GameBackendSDK/demo/SmokeTest.gd").new()
add_child(tests)
๐ง Troubleshooting
"SDK not initialized" error
Call Backend.init() before any other methods.
Requests timeout immediately
Check your timeout_sec setting and network connectivity.
401 errors persist
- Verify backend returns valid tokens
- Check token format (should be Bearer token)
- Ensure refresh endpoint works correctly
Tokens don't persist
Check that user:// directory is writable and not cleared between sessions.
๐ Project Structure
GameBackendSDK/
โโโ addons/
โ โโโ GameBackendSDK/
โ โโโ Backend.gd # Main SDK singleton
โ โโโ internal/
โ โ โโโ HttpClient.gd # HTTP request handling
โ โ โโโ TokenStore.gd # Token persistence
โ โ โโโ Result.gd # Result type helpers
โ โ โโโ Types.gd # Constants & types
โ โ โโโ Backoff.gd # Exponential backoff logic
โ โโโ demo/
โ โ โโโ Demo.tscn # Interactive demo scene
โ โ โโโ SmokeTest.gd # Automated tests
โ โโโ README.md # Detailed SDK documentation
โโโ LICENSE
โโโ README.md
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ฌ Support
- ๐ Full Documentation
- ๐ Report Issues
- ๐ก Request Features
Made with โค๏ธ for the Godot community
Production-ready Godot 4.4+ addon for custom game backends
Authentication, Cloud Saves, Leaderboards, and Remote Config
Reviews
Quick Information
Production-ready Godot 4.4+ addon for custom game backendsAuthentication, Cloud Saves, Leaderboards, and Remote Config