deleteFile
Remove files from your Pinata IPFS storage by specifying the file ID to manage storage space and content organization.
Instructions
Delete a file from your Pinata account by its ID
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| network | No | Whether the file is in public or private IPFS | public |
| id | Yes | The unique ID of the file to delete |
Implementation Reference
- src/index.ts:293-331 (registration)The deleteFile tool is registered here with its schema and handler. It takes parameters for 'network' (public/private IPFS, defaults to public) and 'id' (file ID). The handler makes a DELETE request to the Pinata API to remove the file.
server.tool( "deleteFile", "Delete a file from your Pinata account by its ID", { network: z .enum(["public", "private"]) .default("public") .describe("Whether the file is in public or private IPFS"), id: z.string().describe("The unique ID of the file to delete"), }, async ({ network, id }) => { try { const url = `https://api.pinata.cloud/v3/files/${network}/${id}`; const response = await fetch(url, { method: "DELETE", headers: getHeaders(), }); if (!response.ok) { throw new Error( `Failed to delete file: ${response.status} ${response.statusText}` ); } const data = await response.json(); return { content: [ { type: "text", text: `✅ File deleted successfully\n\n${JSON.stringify(data, null, 2)}`, }, ], }; } catch (error) { return errorResponse(error); } } ); - src/index.ts:296-302 (schema)Schema definition for deleteFile tool parameters using Zod validation: network (enum: 'public' | 'private', default: 'public') and id (required string).
{ network: z .enum(["public", "private"]) .default("public") .describe("Whether the file is in public or private IPFS"), id: z.string().describe("The unique ID of the file to delete"), }, - src/index.ts:303-330 (handler)Handler function for deleteFile that constructs the API URL, makes a DELETE request to Pinata's v3 files endpoint, and returns a success message with the response data or an error response.
async ({ network, id }) => { try { const url = `https://api.pinata.cloud/v3/files/${network}/${id}`; const response = await fetch(url, { method: "DELETE", headers: getHeaders(), }); if (!response.ok) { throw new Error( `Failed to delete file: ${response.status} ${response.statusText}` ); } const data = await response.json(); return { content: [ { type: "text", text: `✅ File deleted successfully\n\n${JSON.stringify(data, null, 2)}`, }, ], }; } catch (error) { return errorResponse(error); } } - src/index.ts:100-108 (helper)Helper function used by deleteFile handler to get authenticated request headers including the JWT Bearer token for Pinata API authentication.
const getHeaders = () => { if (!PINATA_JWT) { throw new Error("PINATA_JWT environment variable is not set"); } return { Authorization: `Bearer ${PINATA_JWT}`, "Content-Type": "application/json", }; }; - src/index.ts:110-119 (helper)Helper function for consistent error responses used by deleteFile handler to format errors in a standardized way with isError flag set to true.
// Helper for consistent error responses const errorResponse = (error: unknown) => ({ content: [ { type: "text" as const, text: `Error: ${error instanceof Error ? error.message : String(error)}`, }, ], isError: true, });