upload_image
Upload images to generate hosted URLs for use in RendrKit templates. Accepts public URLs or base64-encoded image data to create photo_url references.
Instructions
Upload an image to get a hosted URL that can be used as photo_url in templates. Provide either a public URL to re-upload or base64-encoded image data.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | No | Public URL of an image to download and re-upload | |
| base64 | No | Base64-encoded image data | |
| mime_type | No | MIME type of the image (image/jpeg, image/png, image/webp). Required when using base64. |
Implementation Reference
- src/tools/upload-image.ts:31-65 (handler)The main handler function that executes when the upload_image tool is called. It calls client.uploadImage() with the provided parameters and formats the response with the uploaded image's URL, filename, size, and MIME type.
async ({ url, base64, mime_type }) => { try { const result = await client.uploadImage({ url, base64, mimeType: mime_type }); return { content: [ { type: "text" as const, text: [ `Image uploaded successfully!`, ``, `URL: ${result.url}`, `Filename: ${result.filename}`, `Size: ${result.size} bytes`, `Type: ${result.mimeType}`, ``, `Use this URL as image_url or photo_url in generate_image.`, ].join("\n"), }, ], }; } catch (error) { const message = error instanceof Error ? error.message : String(error); return { content: [ { type: "text" as const, text: `Failed to upload image: ${message}`, }, ], isError: true, }; } }, - src/tools/upload-image.ts:14-29 (schema)Input schema definition using Zod for the upload_image tool. Defines three optional parameters: url (public URL to re-upload), base64 (encoded image data), and mime_type (MIME type required when using base64).
inputSchema: { url: z .string() .optional() .describe("Public URL of an image to download and re-upload"), base64: z .string() .optional() .describe("Base64-encoded image data"), mime_type: z .string() .optional() .describe( "MIME type of the image (image/jpeg, image/png, image/webp). Required when using base64.", ), }, - src/types.ts:114-119 (schema)Output schema definition for the upload_image tool's response. Defines UploadResult interface with url, filename, size, and mimeType fields.
export interface UploadResult { url: string; filename: string; size: number; mimeType: string; } - src/api-client.ts:15-19 (schema)Type definition for the uploadImage method parameters. Defines UploadImageParams interface with optional url, base64, and mimeType fields.
export interface UploadImageParams { url?: string; base64?: string; mimeType?: string; } - src/api-client.ts:125-131 (helper)API client method that performs the actual HTTP request to upload an image. Constructs the request body with provided parameters and makes a POST request to /api/v1/upload endpoint.
async uploadImage(params: UploadImageParams): Promise<UploadResult> { const body: Record<string, unknown> = {}; if (params.url) body.url = params.url; if (params.base64) body.base64 = params.base64; if (params.mimeType) body.mimeType = params.mimeType; return this.request<UploadResult>("POST", "/api/v1/upload", body); }