Skip to main content
Glama
phuihock
by phuihock

image_classification

Classify images using AI to identify content and objects through computer vision analysis.

Instructions

Classify an image using DeepInfra OpenAI-compatible API with multimodal model.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
image_urlYes

Implementation Reference

  • The core handler function for the 'image_classification' tool. It takes an image URL, uses a configurable vision model (default: openai/gpt-4o-mini via DeepInfra) to analyze and classify the image contents, prompting for JSON output with categories and confidence scores.
    async def image_classification(image_url: str) -> str:
        """Classify an image using DeepInfra OpenAI-compatible API with multimodal model."""
        model = DEFAULT_MODELS["image_classification"]
        try:
            response = await client.chat.completions.create(
                model=model,
                messages=[
                    {
                        "role": "user",
                        "content": [
                            {
                                "type": "text",
                                "text": "Analyze this image and classify what it shows. Provide the main categories and objects visible in the image with confidence scores. Format as JSON."
                            },
                            {
                                "type": "image_url",
                                "image_url": {"url": image_url}
                            }
                        ]
                    }
                ],
                max_tokens=500,
            )
            if response.choices:
                return response.choices[0].message.content
            else:
                return "Unable to classify image"
        except Exception as e:
            return f"Error classifying image: {type(e).__name__}: {str(e)}"
  • The @app.tool() decorator registers the image_classification function as an MCP tool, conditional on ENABLED_TOOLS configuration (lines 184).
    @app.tool()
  • Configuration of the default model for image_classification tool in DEFAULT_MODELS dictionary.
    "image_classification": os.getenv("MODEL_IMAGE_CLASSIFICATION", "openai/gpt-4o-mini"),
  • Function signature defining input (image_url: str) and output (str) schema for the tool, used by FastMCP for validation.
    async def image_classification(image_url: str) -> str:

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/phuihock/mcp-deeinfra'

If you have feedback or need assistance with the MCP directory API, please join our Discord server