-
Notifications
You must be signed in to change notification settings - Fork 1
Quick Reference
This page only covers generic SDK utilities and addons. It intentionally avoids detailed
client.API.*business API coverage.
steam-go is not only a Steam Web API wrapper. It also provides a practical toolkit for real-world network execution:
- Client construction and configuration
- API key / access token management
- Retry, backoff, and rate limiting
- Proxy selection and health-checked proxy pools
- Per-traffic-class request policies
- Store-page browser-like headers, Referer, short cache, and block detection
- OpenID and A2S addons
- Unified error model and URL redaction
A simple mental model:
steam-go = Steam Web API Client + Network Policy Toolkit + Steam Addons
-
steam-go Toolkit Feature Quick Reference
- Purpose
- Table of Contents
- 1. Client Configuration
- 2. Credential Management
- 3. Retry, Backoff, and Rate Limiting
- 4. Response Body Size Limit
- 5. Custom HTTP Capabilities
- 6. Proxy System
- 7. Traffic Policy
- 8. Store Page Header Profiles
- 9. Referer Policies
- 10. Short Cache and Conditional Requests
- 11. Block Detection
- 12. Host / Session Controls
- 13. TransportHook Extension Point
- 14. OpenID Addon
- 15. A2S Addon
- 16. Error Model
- 17. URL Redaction
- 18. Feature Summary Table
NewClient is the root entrypoint of the SDK. It uses functional options to compose toolkit features.
client, err := steam.NewClient(
steam.WithTimeout(10*time.Second),
steam.WithSafeDefaults(),
)
if err != nil {
panic(err)
}
defer client.Close()WithSafeDefaults() enables a conservative external-traffic preset:
retry = 2
rate limit = 3 requests/second
burst = 3
This is a good starting point before tuning per-service behavior.
client, err := steam.NewClient(
steam.WithAPIKey("your-steam-web-api-key"),
)Purpose:
Automatically inject a Steam Web API key into requests.
client, err := steam.NewClient(
steam.WithAccessToken("your-access-token"),
)Purpose:
Prepare a default access token for endpoints that need one.
client, err := steam.NewClient(
steam.WithAPIKeys("key-a", "key-b", "key-c"),
)Purpose:
Rotate across multiple keys to avoid hitting the same key too often.
client, err := steam.NewClient(
steam.WithHealthCheckedAPIKeys(
steam.DefaultAPIKeyHealthConfig(),
"key-a",
"key-b",
),
steam.WithRetry(2),
)Purpose:
When a key repeatedly hits 401 / 429, it enters a temporary cooldown and later requests prefer other keys.
client, err := steam.NewClient(
steam.WithAPIKeyProvider(myProvider),
steam.WithAccessTokenProvider(myTokenProvider),
)Purpose:
Use this when keys or tokens come from a database, config center, KMS, or dynamic refresh logic.
client, err := steam.NewClient(
steam.WithRetry(2),
)Purpose:
Handle temporary network failures, 429, and 5xx responses.
client, err := steam.NewClient(
steam.WithRetry(3),
steam.WithRetryBackoff(300*time.Millisecond, 3*time.Second),
steam.WithRetryRespectRetryAfter(true),
)Purpose:
Control retry delay and allow Retry-After to override local backoff.
client, err := steam.NewClient(
steam.WithRateLimit(3),
)Purpose:
Limit overall request speed, for example 3 requests per second.
client, err := steam.NewClient(
steam.WithRateLimiter(rate.Limit(5), 10),
)Purpose:
Tune limit and burst more precisely.
client, err := steam.NewClient(
steam.WithMaxResponseBodyBytes(8 << 20),
)Purpose:
Limit how many bytes the SDK buffers for one response body.
This protects clients from unexpected huge HTML pages, error pages, or large JSON payloads.
The SDK already has a default cap. Production applications should tune it explicitly when needed.
client, err := steam.NewClient(
steam.WithBaseURL("http://127.0.0.1:8080"),
)Purpose:
Local mocks, testing gateways, internal proxies, or record/replay tests.
httpClient := &http.Client{
Timeout: 15 * time.Second,
}
client, err := steam.NewClient(
steam.WithHTTPClient(httpClient),
)Purpose:
Reuse the caller's existing HTTP client settings.
client, err := steam.NewClient(
steam.WithDefaultCookieJar(),
)Purpose:
Keep cookie state for OpenID, public pages, or future session-based page flows.
You can also provide your own jar:
client, err := steam.NewClient(
steam.WithCookieJar(myJar),
)Proxy support is centered around the ProxySelector abstraction.
type ProxySelector interface {
Next(req *http.Request) (*url.URL, error)
}selector, err := steam.NewStaticProxySelector("http://127.0.0.1:7897")
if err != nil {
panic(err)
}
client, err := steam.NewClient(
steam.WithProxySelector(selector),
)Purpose:
Route all requests through one fixed proxy.
selector, err := steam.NewRoundRobinProxySelector(
"http://127.0.0.1:7897",
"http://127.0.0.1:7898",
)
client, err := steam.NewClient(
steam.WithProxySelector(selector),
)Purpose:
Rotate requests across multiple proxies.
selector, err := steam.NewHealthCheckedRoundRobinProxySelector(
steam.DefaultProxyHealthConfig(),
"http://127.0.0.1:7897",
"http://127.0.0.1:7898",
)
client, err := steam.NewClient(
steam.WithProxySelector(selector),
)
metrics := selector.(steam.ProxyMetricsProvider).ProxyMetricsSnapshot()
fmt.Printf("healthy=%d cooling=%d\n", metrics.HealthyProxies, metrics.CoolingProxies)Purpose:
When a proxy repeatedly fails, it enters cooldown and is skipped temporarily.
baseSelector, err := steam.NewRoundRobinProxySelector(
"http://127.0.0.1:7897",
"http://127.0.0.1:7898",
)
sticky := steam.NewStickyProxySelector(baseSelector)
client, err := steam.NewClient(
steam.WithProxySelector(sticky),
)
ctx := steam.WithProxySessionKey(context.Background(), "browser-session-1")
_ = ctxPurpose:
Keep the same proxy for the same explicit session key.
Useful for browser sessions, login-like flows, and OpenID callback verification.
selector, err := steam.NewRoutingProxySelector(
steam.ProxyRoute{
Host: "api.steampowered.com",
PathPrefix: "/ISteamUser/",
ProxyURL: "http://127.0.0.1:7897",
},
steam.ProxyRoute{
Host: "steamcommunity.com",
PathPrefix: "/openid/",
ProxyURL: "",
},
)Purpose:
Choose different proxies by host and path.
An empty ProxyURL means direct connection.
selector, _ := steam.NewStaticProxySelector("http://127.0.0.1:7897")
httpClient, err := steam.NewHTTPClientWithProxySelector(
selector,
10*time.Second,
)Purpose:
Reuse the same proxy selection logic for addons or non-core SDK HTTP flows.
TrafficPolicy lets different request categories use different execution strategies.
Current core traffic classes:
steam.TrafficClassOfficialAPI
steam.TrafficClassPublicStorePageclient, err := steam.NewClient(
steam.WithTrafficPolicy(
steam.TrafficClassPublicStorePage,
steam.TrafficPolicy{
RateLimiter: &steam.TrafficRateLimiterPolicy{
Limit: 10,
Burst: 10,
},
},
),
)Purpose:
Official API traffic and public Store page traffic can use different rate limits.
ctx := steam.WithTrafficClass(
context.Background(),
steam.TrafficClassPublicStorePage,
)Purpose:
Force one request into a specific traffic class.
steam.TrafficPolicy{
ProxySelector: proxySelector,
CookieJar: cookieJar,
RateLimiter: rateLimiter,
Retry: retryPolicy,
HostControl: hostControl,
SessionControl: sessionControl,
Cache: cachePolicy,
BlockPolicy: blockPolicy,
HeaderProfile: headerProfile,
RefererSelector: refererSelector,
TransportHook: hook,
}Mental model:
TrafficPolicy = per-traffic-class proxy, cookies, retry, rate limit, cache, headers, Referer, and transport extension.
profile := steam.DefaultPublicStoreHeaderProfileZH()
client, err := steam.NewClient(
steam.WithTrafficPolicy(
steam.TrafficClassPublicStorePage,
steam.TrafficPolicy{
HeaderProfile: &profile,
},
),
)profile := steam.DefaultPublicStoreHeaderProfileEN()Purpose:
Use browser-like User-Agent, Accept, Accept-Language, and related headers for public Store page requests.
referer, err := steam.NewStaticRefererSelector(
"https://store.steampowered.com/search/",
)
client, err := steam.NewClient(
steam.WithTrafficPolicy(
steam.TrafficClassPublicStorePage,
steam.TrafficPolicy{
RefererSelector: referer,
},
),
)referer, err := steam.NewRoutingRefererSelector(
steam.RefererRoute{
Host: "store.steampowered.com",
PathPrefix: "/app/",
RefererURL: "https://store.steampowered.com/",
},
)fallback, _ := steam.NewStaticRefererSelector("https://store.steampowered.com/")
selector := steam.NewContextRefererSelector(fallback)
ctx := steam.WithRefererSource(
context.Background(),
"https://store.steampowered.com/app/730/",
)
_ = selector
_ = ctxPurpose:
Make a request look like it comes from a specific page transition.
client, err := steam.NewClient(
steam.WithTrafficPolicy(
steam.TrafficClassPublicStorePage,
steam.TrafficPolicy{
Cache: &steam.TrafficCachePolicy{
TTL: time.Minute,
},
},
),
)Purpose:
Reuse short-lived GET responses.
Support conditional requests with ETag / Last-Modified revalidation.
Good fits:
Public Store pages
Public HTML
Resources that do not change frequently
client, err := steam.NewClient(
steam.WithTrafficPolicy(
steam.TrafficClassPublicStorePage,
steam.TrafficPolicy{
BlockPolicy: &steam.TrafficBlockPolicy{
HTMLSniffBytes: 4096,
},
},
),
)Purpose:
Detect 429, 403, HTML challenge pages, and suspicious block responses.
It mainly applies to:
TrafficClassPublicStorePage
It should not be treated as a default behavior for normal official API calls.
client, err := steam.NewClient(
steam.WithTrafficPolicy(
steam.TrafficClassPublicStorePage,
steam.TrafficPolicy{
HostControl: &steam.TrafficHostControlPolicy{
MaxConcurrent: 2,
RateLimiter: &steam.TrafficRateLimiterPolicy{
Limit: 2,
Burst: 2,
},
},
},
),
)Purpose:
Control max concurrency and request rate for the same host.
ctx := steam.WithRequestSessionKey(context.Background(), "user-session-1")
client, err := steam.NewClient(
steam.WithTrafficPolicy(
steam.TrafficClassPublicStorePage,
steam.TrafficPolicy{
SessionControl: &steam.TrafficSessionControlPolicy{
MaxConcurrent: 1,
},
},
),
)
_ = ctxPurpose:
Limit concurrency for the same request session.
Useful for login-like flows, browser-like page flows, and Store page access.
TransportHook is a low-level HTTP execution stack extension point.
client, err := steam.NewClient(
steam.WithTrafficPolicy(
steam.TrafficClassPublicStorePage,
steam.TrafficPolicy{
TransportHook: steam.TransportHookFunc(
func(class steam.TrafficClass, base *http.Client) (*http.Client, error) {
cloned := *base
return &cloned, nil
},
),
},
),
)Purpose:
Replace or wrap the HTTP execution stack at the traffic-class level when normal http.Client settings are not enough.
Useful for future extensions:
TLS tuning
Custom Transport
Browser-backed fallback
More complex proxy adaptation
addons/openid is used for browser-based Steam sign-in verification.
What it does:
1. Build the Steam OpenID login URL
2. Verify the Steam callback
3. Call check_authentication
4. Return SteamID64, ClaimedID, and state
What it does not do:
It does not replace a Steam Web API key.
It does not fetch user profile data automatically.
It does not manage your application session.
Run the example:
go run ./examples/openidRun with a proxy:
go run ./examples/openid --proxy http://127.0.0.1:7897Purpose:
Use it when your website needs "Sign in through Steam".
addons/a2s is a lightweight bridge for A2S server queries.
Purpose:
Query game servers directly instead of calling the Steam Web API.
go run ./examples/a2s -server 1.2.3.4:27015 -query infogo run ./examples/a2s -server 1.2.3.4:27015 -query playersgo run ./examples/a2s -server 1.2.3.4:27015 -query rulesRelated addons:
addons/a2s
addons/a2s/master
addons/a2s/scanner
Mental model:
Web API queries Steam platform data.
A2S queries specific game server data.
SDK errors use *steam.APIError.
Error stages:
request_build
transport
http_status
decode
api_response
Example:
var apiErr *steam.APIError
if errors.As(err, &apiErr) {
fmt.Println(apiErr.Kind)
fmt.Println(apiErr.StatusCode)
fmt.Println(apiErr.BodyPreview)
}Purpose:
Quickly identify whether an error happened during request construction, transport, HTTP status handling, response decoding, or API response validation.
Steam key and access_token values are often passed through query parameters. Do not log raw URLs in production.
safeURL := steam.RedactSensitiveURL(
"https://api.steampowered.com/xxx?key=SECRET&access_token=TOKEN&x=1",
)
fmt.Println(safeURL)
// https://api.steampowered.com/xxx?x=1Purpose:
Remove sensitive query parameters before writing URLs to logs, traces, or error reporting systems.
| Feature | Purpose | Typical Use Case |
|---|---|---|
NewClient |
Create SDK client | Root entrypoint |
WithSafeDefaults |
Conservative external-traffic preset | Quick safe setup |
WithAPIKey |
Static API key | Normal Web API calls |
WithAPIKeys |
Rotating API keys | Multi-key scheduling |
WithHealthCheckedAPIKeys |
Key cooldown on repeated failures | 401 / 429 handling |
WithAccessToken |
Static access token | User-authorized endpoints |
WithRetry |
Retry requests | Network jitter, 5xx, 429 |
WithRetryBackoff |
Tune retry delay | Controlled retry rhythm |
WithRateLimit |
Simple rate limit | Avoid sending too fast |
WithRateLimiter |
Token bucket | Fine-grained rate limiting |
WithMaxResponseBodyBytes |
Response body cap | Protect memory |
WithHTTPClient |
Inject HTTP client | Reuse custom HTTP stack |
WithCookieJar |
Cookie session | OpenID / page requests |
ProxySelector |
Proxy selection abstraction | Root of proxy features |
NewStaticProxySelector |
Static proxy | Single proxy |
NewRoundRobinProxySelector |
Round-robin proxies | Multiple proxies |
NewHealthCheckedRoundRobinProxySelector |
Proxy cooldown on failures | Proxy pool |
NewStickyProxySelector |
Sticky proxy | Login / session flows |
NewRoutingProxySelector |
Routing proxy | Split by host/path |
TrafficPolicy |
Per-class request strategy | API / Store page separation |
HeaderProfile |
Browser-like headers | Store pages |
RefererSelector |
Referer management | Page transition simulation |
TrafficCachePolicy |
Short cache | Repeated GET |
TrafficBlockPolicy |
Block detection | Store-page risk handling |
HostControl |
Host-level concurrency control | Single-domain protection |
SessionControl |
Session-level concurrency control | Single-user / session protection |
TransportHook |
HTTP stack extension | Advanced customization |
addons/openid |
Steam sign-in verification | Website login |
addons/a2s |
Game server queries | Server info / players / rules |
APIError |
Unified error model | Error classification |
RedactSensitiveURL |
URL redaction | Log safety |
____ ____ ____ _ _ ____ ____ _ _ / ____ ___ ____ ____ _ _ ____ ____
| __ | | |___ | | |__/ |__/ \_/ / [__ | |___ |__| |\/| __ | __ | |
|__] |__| | |__| | \ | \ | / ___] | |___ | | | | |__] |__|
- SteamID Model
- Steam Web API Notes
- Public Store Page Access Notes
- Partner API Notes
- OpenID Notes
- A2S Notes
- Steam Keys and Access Tokens
- Steam Static Assets
- Steam VDF and addons/vdf
- Steam Web API 特性说明
- 公开商店页面访问说明
- Partner API 说明
- OpenID 说明
- A2S 说明
- Steam Key 与 Access Token
- Steam 静态资源
- Steam VDF 与 addons/vdf