|
1 | 1 | <h1><img src="https://dicebear.com/logo-readme.svg" width="28" /> DiceBear API</h1> |
2 | 2 |
|
3 | | -This is the source code for the [DiceBear API](https://dicebear.com/how-to-use/http-api). It's built on [Fastify](https://fastify.io/). |
4 | | -Learn how to set up your own instance of the API in the [documentation](https://dicebear.com/guides/host-the-http-api-yourself). |
| 3 | +Self-host the DiceBear avatar API for privacy-by-design and commercial use. Built on [Fastify](https://fastify.io/). |
5 | 4 |
|
6 | 5 | [Playground](https://dicebear.com/playground/) | |
7 | | -[Documentation](https://dicebear.com/guides/host-the-http-api-yourself/) |
| 6 | +[Documentation](https://dicebear.com/guides/host-the-http-api-yourself/) | |
| 7 | +[Docker Hub](https://hub.docker.com/r/dicebear/api) |
| 8 | + |
| 9 | +## Getting Started |
| 10 | + |
| 11 | +### With Docker |
| 12 | + |
| 13 | +```sh |
| 14 | +docker run --tmpfs /run --tmpfs /tmp -p 3000:3000 -i -t dicebear/api:3 |
| 15 | +``` |
| 16 | + |
| 17 | +Or with `docker-compose.yml`: |
| 18 | + |
| 19 | +```yaml |
| 20 | +services: |
| 21 | + dicebear: |
| 22 | + image: dicebear/api:3 |
| 23 | + restart: always |
| 24 | + ports: |
| 25 | + - '3000:3000' |
| 26 | + tmpfs: |
| 27 | + - '/run' |
| 28 | + - '/tmp' |
| 29 | +``` |
| 30 | +
|
| 31 | +### Without Docker |
| 32 | +
|
| 33 | +Requires [Node.js](https://nodejs.org/). |
| 34 | +
|
| 35 | +```sh |
| 36 | +git clone git@github.com:dicebear/api.git |
| 37 | +cd api |
| 38 | + |
| 39 | +npm install |
| 40 | +npm run build |
| 41 | +npm start |
| 42 | +``` |
| 43 | + |
| 44 | +## Environment Variables |
| 45 | + |
| 46 | +| Variable | Default | Description | |
| 47 | +| ---------------------------------- | ----------- | ---------------------------------------------------------- | |
| 48 | +| `PORT` | `3000` | Port to listen on. | |
| 49 | +| `HOST` | `0.0.0.0` | Host to bind to (all IPv4 addresses by default). | |
| 50 | +| `LOGGER` | `0` | Enable request logger (1 = on, 0 = off). | |
| 51 | +| `WORKERS` | `1` | Number of Node.js worker threads. | |
| 52 | +| `VERSIONS` | `5,6,7,8,9` | Comma-separated list of supported DiceBear major versions. | |
| 53 | +| `CACHE_CONTROL_AVATARS` | `31536000` | Cache duration for avatar responses in seconds (1 year). | |
| 54 | +| `PNG` | `1` | Enable the PNG endpoint (1 = on, 0 = off). | |
| 55 | +| `PNG_SIZE_MIN` | `1` | Minimum allowed PNG size in px. | |
| 56 | +| `PNG_SIZE_MAX` | `256` | Maximum allowed PNG size in px. | |
| 57 | +| `PNG_SIZE_DEFAULT` | `128` | Default PNG size in px. | |
| 58 | +| `PNG_EXIF` | `1` | Enable EXIF metadata for PNG (1 = on, 0 = off). | |
| 59 | +| `JPEG` | `1` | Enable the JPEG endpoint (1 = on, 0 = off). | |
| 60 | +| `JPEG_SIZE_MIN` | `1` | Minimum allowed JPEG size in px. | |
| 61 | +| `JPEG_SIZE_MAX` | `256` | Maximum allowed JPEG size in px. | |
| 62 | +| `JPEG_SIZE_DEFAULT` | `128` | Default JPEG size in px. | |
| 63 | +| `JPEG_EXIF` | `1` | Enable EXIF metadata for JPEG (1 = on, 0 = off). | |
| 64 | +| `WEBP` | `1` | Enable the WebP endpoint (1 = on, 0 = off). | |
| 65 | +| `WEBP_SIZE_MIN` | `1` | Minimum allowed WebP size in px. | |
| 66 | +| `WEBP_SIZE_MAX` | `256` | Maximum allowed WebP size in px. | |
| 67 | +| `WEBP_SIZE_DEFAULT` | `128` | Default WebP size in px. | |
| 68 | +| `WEBP_EXIF` | `1` | Enable EXIF metadata for WebP (1 = on, 0 = off). | |
| 69 | +| `AVIF` | `1` | Enable the AVIF endpoint (1 = on, 0 = off). | |
| 70 | +| `AVIF_SIZE_MIN` | `1` | Minimum allowed AVIF size in px. | |
| 71 | +| `AVIF_SIZE_MAX` | `256` | Maximum allowed AVIF size in px. | |
| 72 | +| `AVIF_SIZE_DEFAULT` | `128` | Default AVIF size in px. | |
| 73 | +| `AVIF_EXIF` | `1` | Enable EXIF metadata for AVIF (1 = on, 0 = off). | |
| 74 | +| `JSON` | `1` | Enable the JSON endpoint (1 = on, 0 = off). | |
| 75 | +| `QUERY_STRING_ARRAY_LIMIT_MIN` | `20` | Minimum number of values allowed per array parameter. | |
| 76 | +| `QUERY_STRING_PARAMETER_LIMIT_MIN` | `100` | Minimum number of query string parameters allowed. | |
| 77 | + |
| 78 | +> [!NOTE] |
| 79 | +> The `*_EXIF` variables require [Perl](https://www.npmjs.com/package/exiftool-vendored#installation) and [procps](https://www.npmjs.com/package/exiftool-vendored#this-package-requires-procps) to be installed. |
8 | 80 |
|
9 | 81 | ## Sponsors |
10 | 82 |
|
|
0 commit comments