Skip to content

Add x-cog-accept MIME type annotation for Path/File input fields#2863

Open
markphelps wants to merge 2 commits intomainfrom
mphelps/mime-type-input-schema
Open

Add x-cog-accept MIME type annotation for Path/File input fields#2863
markphelps wants to merge 2 commits intomainfrom
mphelps/mime-type-input-schema

Conversation

@markphelps
Copy link
Contributor

@markphelps markphelps commented Mar 24, 2026

Summary

  • Adds an accept parameter to Input() for declaring allowed MIME types / file extensions on Path and File inputs (e.g. Input(accept="image/*"), Input(accept="audio/wav,audio/mp3"), Input(accept=".safetensors,.bin"))
  • The Go static schema generator extracts this and emits x-cog-accept in the OpenAPI schema, giving schema consumers (UIs, validators, API clients) visibility into what file types an input expects
  • Using accept on non-Path/File types (e.g. str, int) is a hard build error

Example

class Predictor(BasePredictor):
    def predict(
        self,
        image: Path = Input(description="Input image", accept="image/*"),
        audio: Path = Input(description="Audio clip", accept="audio/wav,audio/mp3"),
    ) -> Path:
        ...

Produces:

{
  "image": {
    "type": "string",
    "format": "uri",
    "x-cog-accept": "image/*"
  },
  "audio": {
    "type": "string",
    "format": "uri",
    "x-cog-accept": "audio/wav,audio/mp3"
  }
}

Add an 'accept' parameter to Input() that specifies allowed MIME types
or file extensions for Path/File inputs. The Go static schema generator
extracts this and emits it as 'x-cog-accept' in the OpenAPI schema,
giving schema consumers (UIs, validators, API clients) visibility into
what file types an input expects.

Usage: Input(accept="image/*"), Input(accept="audio/wav,audio/mp3"),
or Input(accept=".safetensors,.bin"). Using accept on non-Path/File
types is a hard build error.
@markphelps markphelps marked this pull request as ready for review March 24, 2026 22:22
@markphelps markphelps requested a review from a team as a code owner March 24, 2026 22:22
@markphelps markphelps added this to the 0.18.0 milestone Mar 24, 2026
@markphelps markphelps requested a review from michaeldwan March 24, 2026 22:25
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.

1 participant