# _request_id

URL: /pounce/api/_request_id/
Section: api
Description: Request ID generation and propagation.

Each request gets a unique ID for tracing across logs and services.
If a trusted proxy sends X-Request-ID, we honour it.  Otherwise, we
generate a new one.  The ID is injected into:

- The ASGI scope extensions (``scope["extensions"]["request_id"]``)
- The response headers (``X-Request-ID``)

Uses UUID4 for uniqueness without coordination between workers.

---

> For a complete page index, fetch /pounce/llms.txt.

Open LLM text
(/pounce/api/_request_id/index.txt)

Share with AI

Ask Claude
(https://claude.ai/new?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fpounce%2Fapi%2F_request_id%2Findex.txt)

Ask ChatGPT
(https://chatgpt.com/?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fpounce%2Fapi%2F_request_id%2Findex.txt)

Ask Gemini
(https://gemini.google.com/app?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fpounce%2Fapi%2F_request_id%2Findex.txt)

Ask Copilot
(https://copilot.microsoft.com/?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fpounce%2Fapi%2F_request_id%2Findex.txt)

Module

#
`_request_id`

Request ID generation and propagation.

Each request gets a unique ID for tracing across logs and services.
If a trusted proxy sends X-Request-ID, we honour it. Otherwise, we
generate a new one. The ID is injected into:

- The ASGI scope extensions (`scope["extensions"]["request_id"]`)

- The response headers (`X-Request-ID`)

Uses UUID4 for uniqueness without coordination between workers.

2Functions

## Functions

`generate_request_id`

0

`str`

▼

Generate a unique request ID (UUID4 hex, no dashes).

`def generate_request_id() -> str`

##### Returns

`str`

`extract_or_generate`

2

`str`

▼

Extract X-Request-ID from headers or generate a new one.

If the peer is truste…

`def extract_or_generate(headers: tuple[tuple[bytes, bytes], ...], *, trusted: bool) -> str`

Extract X-Request-ID from headers or generate a new one.

If the peer is trusted (via proxy headers) and sends X-Request-ID,
we use that value. Otherwise, we generate a new UUID4.

##### Parameters

Name
Type
Description

`headers`
`tuple[tuple[bytes, bytes], ...]`

Request headers as (name, value) tuples.

`trusted`
`bool`

Whether the direct peer is trusted (proxy).

##### Returns

`str`
