Skip to content

Conversation

@zeke
Copy link
Member

@zeke zeke commented Nov 21, 2025

This experimental PR adds a new cog.Image type that extends cog.Path to provide image-specific handling in model inputs and outputs.

The Image type works identically to Path but produces OpenAPI schemas with format: "uri" and x-cog-type: "image", following the same pattern as streaming outputs that use x-cog-array-type: "iterator". This allows UIs to provide image-specific widgets while correctly identifying the value as a URI.

Example usage

from cog import BasePredictor, Input, Image
import tempfile

class Predictor(BasePredictor):
    def predict(self, image: Image = Input(description="Input image")) -> Image:
        processed_image = do_some_processing(image)
        
        output_path = Image(tempfile.mkdtemp()) / "processed.png"
        processed_image.save(output_path)
        return Image(output_path)

OpenAPI schema

The generated OpenAPI schema for an Image input:

{
  "image": {
    "title": "Image",
    "description": "An input image",
    "type": "string",
    "format": "uri",
    "x-cog-type": "image"
  }
}

Related:

zeke added 3 commits November 21, 2025 11:09
This PR adds a new `cog.Image` type that extends `cog.Path` to provide
image-specific handling in model inputs and outputs.

The Image type works identically to Path but produces OpenAPI schemas
with `format: "uri"` and `x-cog-type: "image"`, following the same
pattern as streaming outputs that use `x-cog-array-type: "iterator"`.
This allows UIs to provide image-specific widgets while correctly
identifying the value as a URI.

Changes:
- Add Image class in cog/types.py with Pydantic v1 and v2 support
- Export Image from cog package
- Update AST-based OpenAPI schema generation to handle Image type
- Add comprehensive unit and integration tests
- Update documentation with Image type examples
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants