Sign inSign up

limbolabs/discord-api-proxy

By limbolabs

•Updated about 1 year ago

A transparent proxy for handling Discord's API ratelimits.

Image
0

100K+

limbolabs/discord-api-proxy repository overview

⁠Discord API Proxy

A transparent, Redis backed proxy for handling Discord's API ratelimits.

⁠Usage

The easiest way to run the proxy for yourself is Docker, images are available here⁠.

docker run -d \
  -p 8080:8080 \
  -e HOST=0.0.0.0 \
  -e REDIS_HOST=redis \
  limbolabs/discord-api-proxy

Once up and running, just send your normal requests to http://YOURPROXY/api/v* instead of https://discord.com/api/v*.

You'll get back all the same responses, except when you would have hit a ratelimit - then you'll get a 429 from the proxy with x-sent-by-proxy and x-ratelimit-bucket headers.

If you get a 429 from the proxy, you should just retry until it works. If it's happening a lot, just stop hitting them.

⁠Environment Variables
NameDescription
HOSTThe host to listen on. Defaults to 127.0.0.1.
PORTThe port to listen on. Defaults to 8080.
REDIS_HOSTThe host of the Redis server. Defaults to 127.0.0.1.
REDIS_PORTThe port of the Redis server. Defaults to 6379.
REDIS_USERThe host of the Redis server. Defaults to an empty string, is only available on Redis 6+`.
REDIS_PASSThe host of the Redis server. If unset, auth is disabled.
REDIS_POOL_SIZEThe size of the Redis connection pool. Defaults to 64. Note: At least one connection is always reserved for PubSub.
ENABLE_METRICSWhether to expose Prometheus metrics on /metrics. Defaults to true.
LOCK_WAIT_TIMEOUTDuration (in ms) a request should wait for a lock to be released before retrying. Defaults to 500.
RATELIMIT_ABORT_PERIODIf the proxy does ever hit a 429, the duration (in ms) it should abort all incoming requests with a 503 for. Defaults to 1000.

⁠Warnings

⁠Reduced Throughput

When sending globally ratelimited requests, the proxy currently starts the 1s bucket time from when the first response is received as Discord never provide the exact time. This can cause the proxy to be slightly over-restrictive, with a bot where the global ratelimit is 50 only being allowed up to ~47 requests per second.

⁠Overloading

Under extreme load, Redis calls to check ratelimits may start to slow down, causing the global ratelimit bucket expiry to drift. We try to mitigate this by monitoring the time taken for ratelimit checks and aborting the request when overloaded, but some can still slip through.

In the event that the proxy does receive a 429 from Discord, it will abort all further requests for 1 second.

⁠Credits

Tag summary

Content type

Image

Digest

sha256:f5cddb539…

Size

53.2 MB

Last updated

about 1 year ago

docker pull limbolabs/discord-api-proxy