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

# MediaClient

> Methods for X API v2 Media endpoints.

Access **Media** endpoints via `client.Media` (`MediaClient`).

## Methods

| Method | Endpoint | Behavior | Summary |
| :- | :- | :- | :- |
| [`AddPostToAmplifyProgramsAsync`](#addposttoamplifyprogramsasync) | `POST /2/media/amplify/posts` | Standard | Add Post to Amplify Programs |
| [`AddToLibraryAsync`](#addtolibraryasync) | `POST /2/media/library` | Standard | Add Media to Library |
| [`AppendUploadAsync`](#appenduploadasync) | `POST /2/media/upload/{id}/append` | Standard | Append Media Upload |
| [`CreateMetadataAsync`](#createmetadataasync) | `POST /2/media/metadata` | Standard | Create Media Metadata |
| [`CreateSubtitlesAsync`](#createsubtitlesasync) | `POST /2/media/subtitles` | Standard | Create Media Subtitles |
| [`DeleteSubtitlesAsync`](#deletesubtitlesasync) | `DELETE /2/media/subtitles` | Standard | Delete Media Subtitles |
| [`FinalizeUploadAsync`](#finalizeuploadasync) | `POST /2/media/upload/{id}/finalize` | Standard | Finalize Media Upload |
| [`GetAmplifyProgramAsync`](#getamplifyprogramasync) | `GET /2/media/amplify/programs/{program_id}` | Standard | Get Amplify Program |
| [`GetAmplifyProgramPostsAsync`](#getamplifyprogrampostsasync) | `GET /2/media/amplify/programs/{program_id}/posts` | Standard | Get Amplify Program Posts |
| [`GetAmplifyProgramsAsync`](#getamplifyprogramsasync) | `GET /2/media/amplify/programs` | Standard | Get Amplify Programs |
| [`GetAnalyticsAsync`](#getanalyticsasync) | `GET /2/media/analytics` | Standard | Get Media Analytics |
| [`GetByKeyAsync`](#getbykeyasync) | `GET /2/media/{media_key}` | Standard | Get Media by Media Key |
| [`GetByKeysAsync`](#getbykeysasync) | `GET /2/media` | Standard | Get Media by Media Keys |
| [`GetLibraryCategoriesAsync`](#getlibrarycategoriesasync) | `GET /2/media/library/categories` | Standard | Get Media Library Categories |
| [`GetUploadStatusAsync`](#getuploadstatusasync) | `GET /2/media/upload` | Standard | Get Media Upload Status |
| [`InitializeUploadAsync`](#initializeuploadasync) | `POST /2/media/upload/initialize` | Standard | Initialize Media Upload |
| [`RemoveFromLibraryAsync`](#removefromlibraryasync) | `DELETE /2/media/library/{media_key}` | Standard | Remove Media Library Item |
| [`UpdateInLibraryAsync`](#updateinlibraryasync) | `PUT /2/media/library/{media_key}` | Standard | Update Media Library Item |
| [`UploadAsync`](#uploadasync) | `POST /2/media/upload` | Standard | Upload Media |

## `AddPostToAmplifyProgramsAsync`

POST `/2/media/amplify/posts`

**Add Post to Amplify Programs**

Publishes one of the authenticated user's video posts into one or more active Amplify pre-roll programs the user is enrolled in as a publisher.

```csharp theme={null}
using System;
using System.Collections.Generic;
using Xdk;
using Xdk.Models;

using var client = new XClient(new XClientOptions
{
    AccessToken = Environment.GetEnvironmentVariable("X_ACCESS_TOKEN"),
});

var response = await client.Media.AddPostToAmplifyProgramsAsync(
    new AddPostToAmplifyProgramsRequest { PostId = "1895000000000000000", ProgramIds = new List<string> { "1895000000000000000" } }
);
Console.WriteLine(response);
```

### Parameters

**body** `AddPostToAmplifyProgramsRequest` *required*

Request payload.

**Returns:** `Task<AddPostToAmplifyProgramsResponse>`

***

## `AddToLibraryAsync`

POST `/2/media/library`

**Add Media to Library**

Adds previously uploaded media to the authenticated user's Media Library with its library metadata. The user must own the media. Geo restrictions, content expiry, the preview image and the audience policy are set with the Media metadata endpoint.

```csharp theme={null}
using System;
using Xdk;
using Xdk.Models;

using var client = new XClient(new XClientOptions
{
    AccessToken = Environment.GetEnvironmentVariable("X_ACCESS_TOKEN"),
});

var response = await client.Media.AddToLibraryAsync(new AddMediaToLibraryRequest { MediaKey = "3_1895000000000000000" });
Console.WriteLine(response);
```

### Parameters

**body** `AddMediaToLibraryRequest` *required*

Request payload.

**Returns:** `Task<AddMediaToLibraryResponse>`

***

## `AppendUploadAsync`

POST `/2/media/upload/{id}/append`

**Append Media Upload**

Appends one segment of the file to a chunked upload. Send the segment base64-encoded in media (raw bytes in multipart bodies) and its position in the file in segment\_index, counting from 0. A segment can be up to 8 MB; in a JSON body keep it to 4 MB or less, because base64 adds a third. After the last segment, call Finalize Media Upload.

```csharp theme={null}
using System;
using Xdk;
using Xdk.Models;

using var client = new XClient(new XClientOptions
{
    AccessToken = Environment.GetEnvironmentVariable("X_ACCESS_TOKEN"),
});

var response = await client.Media.AppendUploadAsync(
    "1895000000000000000",
    new AppendMediaUploadRequest { Media = "example", SegmentIndex = 1 }
);
Console.WriteLine(response);
```

### Parameters

**id** `string` *required*

The upload id from Initialize Media Upload.

**body** `AppendMediaUploadRequest` *required*

Request payload.

**Returns:** `Task<AppendMediaUploadResponse>`

***

## `CreateMetadataAsync`

POST `/2/media/metadata`

**Create Media Metadata**

Creates metadata for a Media file.

```csharp theme={null}
using System;
using Xdk;
using Xdk.Models;

using var client = new XClient(new XClientOptions
{
    AccessToken = Environment.GetEnvironmentVariable("X_ACCESS_TOKEN"),
});

var response = await client.Media.CreateMetadataAsync(new CreateMediaMetadataRequest { Id = "1895000000000000000" });
Console.WriteLine(response);
```

### Parameters

**body** `CreateMediaMetadataRequest` *required*

Request payload.

**Returns:** `Task<CreateMediaMetadataResponse>`

***

## `CreateSubtitlesAsync`

POST `/2/media/subtitles`

**Create Media Subtitles**

Creates subtitles for a specific Media file.

```csharp theme={null}
using System;
using Xdk;
using Xdk.Models;

using var client = new XClient(new XClientOptions
{
    AccessToken = Environment.GetEnvironmentVariable("X_ACCESS_TOKEN"),
});

var response = await client.Media.CreateSubtitlesAsync(
    new CreateMediaSubtitlesRequest { Id = "1895000000000000000", MediaCategory = "AmplifyVideo" }
);
Console.WriteLine(response);
```

### Parameters

**body** `CreateMediaSubtitlesRequest` *required*

Request payload.

**Returns:** `Task<CreateMediaSubtitlesResponse>`

***

## `DeleteSubtitlesAsync`

DELETE `/2/media/subtitles`

**Delete Media Subtitles**

Deletes subtitles for a specific Media file.

```csharp theme={null}
using System;
using Xdk;
using Xdk.Models;

using var client = new XClient(new XClientOptions
{
    AccessToken = Environment.GetEnvironmentVariable("X_ACCESS_TOKEN"),
});

var response = await client.Media.DeleteSubtitlesAsync(
    new DeleteMediaSubtitlesRequest { Id = "1895000000000000000", MediaCategory = "example", LanguageCode = "example" }
);
Console.WriteLine(response);
```

### Parameters

**body** `DeleteMediaSubtitlesRequest` *required*

Request payload.

**Returns:** `Task<DeleteMediaSubtitlesResponse>`

***

## `FinalizeUploadAsync`

POST `/2/media/upload/{id}/finalize`

**Finalize Media Upload**

Completes a chunked upload once every segment is appended. For video the result carries processing\_info: the media can go on a Post only when its state is succeeded, so call Get Media Upload Status until it is. A result without processing\_info is ready to use.

```csharp theme={null}
using System;
using Xdk;

using var client = new XClient(new XClientOptions
{
    AccessToken = Environment.GetEnvironmentVariable("X_ACCESS_TOKEN"),
});

var response = await client.Media.FinalizeUploadAsync("1895000000000000000");
Console.WriteLine(response);
```

### Parameters

**id** `string` *required*

The upload id from Initialize Media Upload.

**Returns:** `Task<FinalizeMediaUploadResponse>`

***

## `GetAmplifyProgramAsync`

GET `/2/media/amplify/programs/{program_id}`

**Get Amplify Program**

Returns one Amplify pre-roll program the authenticated user is enrolled in as a publisher. A program the user is not enrolled in is reported as not found.

```csharp theme={null}
using System;
using Xdk;

using var client = new XClient(new XClientOptions
{
    AccessToken = Environment.GetEnvironmentVariable("X_ACCESS_TOKEN"),
});

var response = await client.Media.GetAmplifyProgramAsync("1895000000000000000");
Console.WriteLine(response);
```

### Parameters

**programId** `string` *required*

Identifier of the program.

**Returns:** `Task<GetAmplifyProgramResponse>`

***

## `GetAmplifyProgramPostsAsync`

GET `/2/media/amplify/programs/{program_id}/posts`

**Get Amplify Program Posts**

Returns the posts published into an Amplify pre-roll program the authenticated user is enrolled in as a publisher.

```csharp theme={null}
using System;
using Xdk;

using var client = new XClient(new XClientOptions
{
    AccessToken = Environment.GetEnvironmentVariable("X_ACCESS_TOKEN"),
});

var response = await client.Media.GetAmplifyProgramPostsAsync("1895000000000000000");
Console.WriteLine(response);
```

### Parameters

**programId** `string` *required*

Identifier of the program.

**Returns:** `Task<GetAmplifyProgramPostsResponse>`

***

## `GetAmplifyProgramsAsync`

GET `/2/media/amplify/programs`

**Get Amplify Programs**

Returns the Amplify pre-roll programs the authenticated user is enrolled in as a publisher.

```csharp theme={null}
using System;
using Xdk;

using var client = new XClient(new XClientOptions
{
    AccessToken = Environment.GetEnvironmentVariable("X_ACCESS_TOKEN"),
});

var response = await client.Media.GetAmplifyProgramsAsync();
Console.WriteLine(response);
```

**Returns:** `Task<GetAmplifyProgramsResponse>`

***

## `GetAnalyticsAsync`

GET `/2/media/analytics`

**Get Media Analytics**

Retrieves analytics data for media.

```csharp theme={null}
using System;
using System.Collections.Generic;
using Xdk;

using var client = new XClient(new XClientOptions
{
    AccessToken = Environment.GetEnvironmentVariable("X_ACCESS_TOKEN"),
});

var response = await client.Media.GetAnalyticsAsync(
    new List<string> { "3_1895000000000000000" },
    "2026-01-01T00:00:00Z",
    "2026-01-02T00:00:00Z"
);
Console.WriteLine(response);
```

### Parameters

**mediaKeys** `List\<string\>` *required*

`media_keys` (query parameter).

**startTime** `string` *required*

`start_time` (query parameter).

**endTime** `string` *required*

`end_time` (query parameter).

**Optional parameters (MediaClient.GetAnalyticsOptions — 2)**

**options.Granularity** `string`

`granularity` (query parameter).

**options.MediaAnalyticsFields** `List\<string\>`

A comma separated list of MediaAnalytics fields to display.

**Returns:** `Task<GetMediaAnalyticsResponse>`

***

## `GetByKeyAsync`

GET `/2/media/{media_key}`

**Get Media by Media Key**

Retrieves details of a specific Media file by its media key.

```csharp theme={null}
using System;
using Xdk;

using var client = new XClient(new XClientOptions
{
    BearerToken = Environment.GetEnvironmentVariable("X_BEARER_TOKEN"),
});

var response = await client.Media.GetByKeyAsync("3_1895000000000000000");
Console.WriteLine(response);
```

### Parameters

**mediaKey** `string` *required*

`media_key` (path parameter).

**Optional parameters (MediaClient.GetByKeyOptions — 1)**

**options.MediaFields** `List\<string\>`

A comma separated list of Media fields to display.

**Returns:** `Task<GetMediaByMediaKeyResponse>`

***

## `GetByKeysAsync`

GET `/2/media`

**Get Media by Media Keys**

Retrieves details of Media files by their media keys.

```csharp theme={null}
using System;
using System.Collections.Generic;
using Xdk;

using var client = new XClient(new XClientOptions
{
    BearerToken = Environment.GetEnvironmentVariable("X_BEARER_TOKEN"),
});

var response = await client.Media.GetByKeysAsync(new List<string> { "3_1895000000000000000" });
Console.WriteLine(response);
```

### Parameters

**mediaKeys** `List\<string\>` *required*

`media_keys` (query parameter).

**Optional parameters (MediaClient.GetByKeysOptions — 1)**

**options.MediaFields** `List\<string\>`

A comma separated list of Media fields to display.

**Returns:** `Task<GetMediaByMediaKeysResponse>`

***

## `GetLibraryCategoriesAsync`

GET `/2/media/library/categories`

**Get Media Library Categories**

Returns the video categories a publisher can assign to a media library item and the advertiser categories whose ads can be blocked from running against it.

```csharp theme={null}
using System;
using Xdk;

using var client = new XClient(new XClientOptions
{
    AccessToken = Environment.GetEnvironmentVariable("X_ACCESS_TOKEN"),
});

var response = await client.Media.GetLibraryCategoriesAsync();
Console.WriteLine(response);
```

### Parameters

**Optional parameters (MediaClient.GetLibraryCategoriesOptions — 1)**

**options.Lang** `string`

Language tag for category descriptions, e.g. `en` or `pt-BR`.

**Returns:** `Task<GetMediaLibraryCategoriesResponse>`

***

## `GetUploadStatusAsync`

GET `/2/media/upload`

**Get Media Upload Status**

Returns how far X has processed an uploaded media file, in processing\_info.state: pending, in\_progress, succeeded or failed. Call it after Finalize Media Upload returns processing\_info, waiting check\_after\_secs between calls, until the state is succeeded. A failed state means the media can't be used.

```csharp theme={null}
using System;
using Xdk;

using var client = new XClient(new XClientOptions
{
    AccessToken = Environment.GetEnvironmentVariable("X_ACCESS_TOKEN"),
});

var response = await client.Media.GetUploadStatusAsync("3_1895000000000000000");
Console.WriteLine(response);
```

### Parameters

**mediaId** `string` *required*

The media id from Initialize Media Upload.

**Optional parameters (MediaClient.GetUploadStatusOptions — 1)**

**options.Command** `string`

Always STATUS; can be left out.

**Returns:** `Task<GetMediaUploadStatusResponse>`

***

## `InitializeUploadAsync`

POST `/2/media/upload/initialize`

**Initialize Media Upload**

Starts a chunked media upload and returns its id. Use it for video and for other files too large for one request. For a video on a Post, set media\_category to tweet\_video, media\_type to the file's type (for example video/mp4) and total\_bytes to the file's size. Send the file with Append Media Upload, call Finalize Media Upload, then pass the id in media.media\_ids on Create or Edit Post.

```csharp theme={null}
using System;
using System.Collections.Generic;
using Xdk;
using Xdk.Models;

using var client = new XClient(new XClientOptions
{
    AccessToken = Environment.GetEnvironmentVariable("X_ACCESS_TOKEN"),
});

var response = await client.Media.InitializeUploadAsync(
    new InitializeMediaUploadRequest { AdditionalOwners = new List<string> { "example" } }
);
Console.WriteLine(response);
```

### Parameters

**body** `InitializeMediaUploadRequest` *required*

Request payload.

**Returns:** `Task<InitializeMediaUploadResponse>`

***

## `RemoveFromLibraryAsync`

DELETE `/2/media/library/{media_key}`

**Remove Media Library Item**

Removes an item from the authenticated user's Media Library. Posts scheduled through the API that have not yet been published and still use the media are cancelled. Published posts and the underlying media are not affected.

```csharp theme={null}
using System;
using Xdk;
using Xdk.Models;

using var client = new XClient(new XClientOptions
{
    AccessToken = Environment.GetEnvironmentVariable("X_ACCESS_TOKEN"),
});

var response = await client.Media.RemoveFromLibraryAsync("3_1895000000000000000", new RemoveMediaFromLibraryRequest());
Console.WriteLine(response);
```

### Parameters

**mediaKey** `string` *required*

The media key of the library item to remove.

**body** `RemoveMediaFromLibraryRequest` *required*

Request payload.

**Returns:** `Task<RemoveMediaFromLibraryResponse>`

***

## `UpdateInLibraryAsync`

PUT `/2/media/library/{media_key}`

**Update Media Library Item**

Updates the library metadata of an item in the authenticated user's Media Library. Only the fields sent are changed; the others keep their values. Geo restrictions, content expiry, the preview image and the audience policy are set with the Media metadata endpoint.

```csharp theme={null}
using System;
using Xdk;
using Xdk.Models;

using var client = new XClient(new XClientOptions
{
    AccessToken = Environment.GetEnvironmentVariable("X_ACCESS_TOKEN"),
});

var response = await client.Media.UpdateInLibraryAsync(
    "3_1895000000000000000",
    new UpdateMediaInLibraryRequest { Name = "My List" }
);
Console.WriteLine(response);
```

### Parameters

**mediaKey** `string` *required*

The media key of the library item to update.

**body** `UpdateMediaInLibraryRequest` *required*

Request payload.

**Returns:** `Task<UpdateMediaInLibraryResponse>`

***

## `UploadAsync`

POST `/2/media/upload`

**Upload Media**

Uploads a media file in one request and returns its id. Send the file base64-encoded in media (raw bytes in multipart bodies). For a Post, set media\_category to tweet\_image (JPG, PNG, GIF or WEBP, up to 5 MB) or tweet\_gif, then pass the returned id in media.media\_ids on Create or Edit Post. DM media uses dm\_image or dm\_gif. For video, use Initialize Media Upload.

```csharp theme={null}
using System;
using Xdk;
using Xdk.Models;

using var client = new XClient(new XClientOptions
{
    AccessToken = Environment.GetEnvironmentVariable("X_ACCESS_TOKEN"),
});

var response = await client.Media.UploadAsync(
    new MediaUploadRequest { Media = "example", MediaCategory = "tweet_image" }
);
Console.WriteLine(response);
```

### Parameters

**body** `MediaUploadRequest` *required*

Request payload.

**Returns:** `Task<MediaUploadResponse>`

***
