---
title: "Get a media item by id"
method: GET
path: "/buckets/{slug}/media/{media_id}"
tags: ["Media"]
---

# Get a media item by id

`GET /buckets/{slug}/media/{media_id}`

## Request

- Base URL: `https://api.cosmicjs.com/v3`
- URL: `https://api.cosmicjs.com/v3/buckets/{slug}/media/{media_id}`
- Auth: API key in query parameter `read_key`
- TypeScript: <https://skmtc.dev/cosmicjs/apis/cosmic-rest-api-v3/docs/buckets/:slug/media/:media_id/get.ts> (a function with typed inputs; its response is checked against the schema)

Retrieve a single media item by its id. To fetch by file name instead, query the media list endpoint with `query={"name":"..."}`.

## Query parameters

- `read_key` string
- `props` string
- `useCache` boolean
- `pretty` boolean

## Response `200`

The requested media item.

- MediaResponse
  - `media` Media, required: An image, file, or document in the Bucket.
    - `id` string
    - `name` string: Unique file name within the Bucket. This is the value you assign to a File or Image Metafield.
    - `original_name` string: The file name as uploaded.
    - `size` union: File size in bytes.
      - integer
      - string
    - `type` string: MIME type.
    - `bucket` string: Bucket id.
    - `folder` string, nullable
    - `alt_text` string, nullable: Images only.
    - `width` integer, nullable: Pixel width. Images only.
    - `height` integer, nullable: Pixel height. Images only.
    - `url` string, uri: CDN URL.
    - `imgix_url` string, uri: imgix URL, which accepts image processing query parameters.
    - `metadata` object, nullable: Arbitrary JSON metadata you attach to the media.
    - `created_at` string, date-time

## Other responses

- `400`: The request was invalid, most often a malformed `query` or a Metafield value that failed validation.
- `401`: The access key is missing or incorrect.
- `402`: The Bucket needs to be upgraded before it can be used again.
- `404`: The addressed resource does not exist in this Bucket. Note that this covers a resource missing from a route that exists; an unrecognized route answers 200 with a `Route not found` body instead, as described in the API description above.
- `429`: Too many requests hit the API too quickly. Back off and retry.
- `500`: Something went wrong on the Cosmic side.

---

[API](https://skmtc.dev/cosmicjs/apis/cosmic-rest-api-v3.md) - [All operations](https://skmtc.dev/cosmicjs/apis/cosmic-rest-api-v3/llms.txt) - [OpenAPI document](https://skmtc.dev/cosmicjs/apis/cosmic-rest-api-v3/revisions/e0aa2a0913b3?raw)
