> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bayse.markets/llms.txt
> Use this file to discover all available pages before exploring further.

# Response compression

> Request smaller JSON responses with gzip and automatic client decompression

Successful JSON responses from `GET /v1/pm/*` support gzip compression. Send
`Accept-Encoding: gzip` to opt in. Compression reduces the bytes transferred;
the decoded JSON fields and authentication requirements stay the same.

Browsers normally advertise gzip support automatically. Many HTTP libraries
also negotiate compression and decode responses for you.

## Enable compression

These examples request the public sports-leagues endpoint, which needs no API
key. Keep the usual authentication headers when calling authenticated endpoints.

```bash cURL theme={null}
curl --fail-with-body --silent --show-error --compressed \
  'https://relay.bayse.markets/v1/pm/sports/leagues'
```

```javascript Node.js theme={null}
// Node.js 18+ fetch negotiates compression and decodes the response.
async function main() {
  const response = await fetch(
    'https://relay.bayse.markets/v1/pm/sports/leagues',
    { signal: AbortSignal.timeout(15000) }
  );
  if (!response.ok) {
    throw new Error(`HTTP ${response.status}: ${await response.text()}`);
  }
  console.log(await response.json());
}

main().catch(error => {
  console.error(error);
  process.exitCode = 1;
});
```

```python Python theme={null}
import requests

# Requests negotiates gzip and decodes response content automatically.
try:
    response = requests.get(
        'https://relay.bayse.markets/v1/pm/sports/leagues',
        timeout=15,
    )
    response.raise_for_status()
    print(response.json())
except (requests.RequestException, ValueError) as error:
    raise SystemExit(f'Request failed: {error}')
```

```go Go theme={null}
package main

import (
    "encoding/json"
    "log"
    "net/http"
    "os"
    "time"
)

func main() {
    // The default transport negotiates gzip and decodes it automatically.
    client := &http.Client{Timeout: 15 * time.Second}
    response, err := client.Get("https://relay.bayse.markets/v1/pm/sports/leagues")
    if err != nil {
        log.Fatal(err)
    }
    defer response.Body.Close()
    if response.StatusCode != http.StatusOK {
        log.Fatalf("HTTP %s", response.Status)
    }
    var result any
    if err := json.NewDecoder(response.Body).Decode(&result); err != nil {
        log.Fatal(err)
    }
    if err := json.NewEncoder(os.Stdout).Encode(result); err != nil {
        log.Fatal(err)
    }
}
```

An encoded response includes these headers:

```http theme={null}
HTTP/2 200
Content-Type: application/json; charset=utf-8
Content-Encoding: gzip
Vary: Accept-Encoding
```

After decompression, the response contains ordinary JSON. For example, the
`leagues` array includes entries like this:

```json theme={null}
{
  "name": "England - Premier League",
  "shortName": "EPL",
  "imageUrl": "https://assets.bayse.markets/event-images/leagues/epl.png"
}
```

## Handle both response formats

Allow both gzip and uncompressed responses. Compression applies to eligible
`200 OK` JSON responses of at least 1 KiB. Small responses, errors, write
operations, health checks, range requests, and WebSocket upgrades remain
uncompressed. Responses marked `Cache-Control: no-transform` or carrying an
existing encoding or validator pass through unchanged.

Use your HTTP library's automatic decompression. If you handle raw response
bytes yourself, decompress only when `Content-Encoding` is `gzip`.

> [!NOTE]
>
> With Go's default transport, leave `Accept-Encoding` unset to enable automatic
> gzip negotiation and decompression. If you set that header yourself, you must
> handle decompression yourself. Clients must continue accepting uncompressed
> responses; do not require gzip with `identity;q=0`.

To request an uncompressed response explicitly:

```bash theme={null}
curl --fail-with-body --silent --show-error \
  -H 'Accept-Encoding: identity' \
  'https://relay.bayse.markets/v1/pm/sports/leagues'
```

`gzip;q=0` also disables gzip. Clients that omit `Accept-Encoding` continue to
receive uncompressed responses. Request-body encoding and HMAC signing do not
change.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.