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
| Name | Required | Description | Default |
|---|---|---|---|
| image_url | Yes |
Implementation Reference
- src/mcp_deepinfra/server.py:186-214 (handler)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)}"
- src/mcp_deepinfra/server.py:185-185 (registration)The @app.tool() decorator registers the image_classification function as an MCP tool, conditional on ENABLED_TOOLS configuration (lines 184).@app.tool()
- src/mcp_deepinfra/server.py:38-38 (helper)Configuration of the default model for image_classification tool in DEFAULT_MODELS dictionary."image_classification": os.getenv("MODEL_IMAGE_CLASSIFICATION", "openai/gpt-4o-mini"),
- src/mcp_deepinfra/server.py:186-186 (schema)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: