# How to Fetch CS2 Prices in TypeScript

> Fetch CS2 prices in TypeScript from a Node or Next.js server by requesting `GET /v1/prices/latest`, then select exact item keys from the returned all-market snapshot.

The API key must remain server-side. Do not expose it through a public environment variable, Client Component, or browser request.

## TypeScript request contract

Every `/v1` request requires a bearer authorization header and `Accept-Encoding: gzip`. Server-side `fetch` runtimes commonly decode gzip before exposing the response body, so the integration should follow its runtime's behavior and avoid a second decompression step.

The response contains `response_time`, `currency`, and an `items` record keyed by exact `market_hash_name`. Each item can contain six source objects and a `variants` record for supported Doppler, Gamma Doppler, or Case Hardened phases and tiers.

Type quote and volume fields as nullable. Unsupported or unavailable fields can be null even when the item and source object are present. Keep `updated_at` and `collected_at` as source-level timestamps rather than replacing them with the top-level response time.

## Server-side selection flow

Fetch and validate the full snapshot once per application refresh cycle. Select required items locally, enforce source-age rules using `collected_at`, and retain the source and field that produced a chosen price.

For cash-price selection, compare supported cash-market asks and keep Steam as a separately labeled wallet reference. For variants, index the nested record by its full `name` or stable `version` so a phase request cannot fall back to the base item.

Historical POST requests accept up to 100 exact names and can return valid items beside item-level `errors[]`. Preserve those partial results in a separate typed array rather than converting failed names to zero-price items.

## Applicable endpoints

| Endpoint | Returns | Plans |
| --- | --- | --- |
| `GET /v1/prices/latest` | Current all-item, all-source snapshot | All plans |
| `POST /v1/prices/history` | OHLC history with per-item partial errors | Scale, Enterprise |

## TypeScript integration notes

- Disable framework caching or set an explicit refresh policy that matches the application's allowed staleness. Source prices generally update every ~5-10 minutes.
- Current nulls and missing fields are coverage states. Keep them distinct from numeric zero.
- All plans have unlimited requests at 10 requests per second per user, but one shared snapshot is the coherent input for many lookups.
- Maintained request examples are available in the [current-price reference](/docs/api-reference/prices-latest).
