Image Operations - Analyze Image

Analyze Image
A synchronous API for the analysis of potentially harmful image content. Currently, it supports four categories: Hate, SelfHarm, Sexual, and Violence.

POST {endpoint}/contentsafety/image:analyze?api-version=2023-10-01

URI Parameters

Name In Required Type Description
endpoint
path True

string

Supported Cognitive Services endpoints (protocol and hostname, for example: https://.cognitiveservices.azure.com).

api-version
query True

string

The API version to use for this operation.

Request Body

Name Required Type Description
image True

ImageData

The image to be analyzed.

categories

ImageCategory[]

The categories will be analyzed. If they are not assigned, a default set of analysis results for the categories will be returned.

outputType

AnalyzeImageOutputType

This refers to the type of image analysis output. If no value is assigned, the default value will be "FourSeverityLevels".

Responses

Name Type Description
200 OK

AnalyzeImageResult

The request has succeeded.

Other Status Codes

Azure.Core.Foundations.ErrorResponse

An unexpected error response.

Headers

x-ms-error-code: string

Security

Ocp-Apim-Subscription-Key

Type: apiKey
In: header

OAuth2Auth

Type: oauth2
Flow: application
Token URL: https://login.microsoftonline.com/common/oauth2/v2.0/token

Scopes

Name Description
https://cognitiveservices.azure.com/.default

Examples

Analyze Image

Sample request

POST {endpoint}/contentsafety/image:analyze?api-version=2023-10-01

{
  "image": {
    "content": "Y29udGVudDE="
  }
}

Sample response

{
  "categoriesAnalysis": [
    {
      "category": "Hate",
      "severity": 0
    },
    {
      "category": "SelfHarm",
      "severity": 0
    },
    {
      "category": "Sexual",
      "severity": 0
    },
    {
      "category": "Violence",
      "severity": 2
    }
  ]
}

Definitions

Name Description
AnalyzeImageOptions

The image analysis request.

AnalyzeImageOutputType

This refers to the type of image analysis output. If no value is assigned, the default value will be "FourSeverityLevels".

AnalyzeImageResult

The image analysis response.

Azure.Core.Foundations.Error

The error object.

Azure.Core.Foundations.ErrorResponse

A response containing error details.

Azure.Core.Foundations.InnerError

An object containing more specific information about the error. As per Microsoft One API guidelines - https://github.com/Microsoft/api-guidelines/blob/vNext/Guidelines.md#7102-error-condition-responses.

ImageCategoriesAnalysis

Image analysis result.

ImageCategory

The harm category supported in Image content analysis.

ImageData

The image can be either base64 encoded bytes or a blob URL. You can choose only one of these options. If both are provided, the request will be refused. The maximum image size is 2048 x 2048 pixels and should not exceed 4 MB, while the minimum image size is 50 x 50 pixels.

AnalyzeImageOptions

The image analysis request.

Name Type Default value Description
categories

ImageCategory[]

The categories will be analyzed. If they are not assigned, a default set of analysis results for the categories will be returned.

image

ImageData

The image to be analyzed.

outputType

AnalyzeImageOutputType

FourSeverityLevels

This refers to the type of image analysis output. If no value is assigned, the default value will be "FourSeverityLevels".

AnalyzeImageOutputType

This refers to the type of image analysis output. If no value is assigned, the default value will be "FourSeverityLevels".

Name Type Description
FourSeverityLevels

string

Output severities in four levels, the value could be 0,2,4,6.

AnalyzeImageResult

The image analysis response.

Name Type Description
categoriesAnalysis

ImageCategoriesAnalysis[]

Analysis result for categories.

Azure.Core.Foundations.Error

The error object.

Name Type Description
code

string

One of a server-defined set of error codes.

details

Azure.Core.Foundations.Error[]

An array of details about specific errors that led to this reported error.

innererror

Azure.Core.Foundations.InnerError

An object containing more specific information than the current object about the error.

message

string

A human-readable representation of the error.

target

string

The target of the error.

Azure.Core.Foundations.ErrorResponse

A response containing error details.

Name Type Description
error

Azure.Core.Foundations.Error

The error object.

Azure.Core.Foundations.InnerError

An object containing more specific information about the error. As per Microsoft One API guidelines - https://github.com/Microsoft/api-guidelines/blob/vNext/Guidelines.md#7102-error-condition-responses.

Name Type Description
code

string

One of a server-defined set of error codes.

innererror

Azure.Core.Foundations.InnerError

Inner error.

ImageCategoriesAnalysis

Image analysis result.

Name Type Description
category

ImageCategory

The image analysis category.

severity

integer

The value increases with the severity of the input content. The value of this field is determined by the output type specified in the request. The output type could be ‘FourSeverityLevels’, and the output value can be 0, 2, 4, 6.

ImageCategory

The harm category supported in Image content analysis.

Name Type Description
Hate

string

The harm category for Image - Hate.

SelfHarm

string

The harm category for Image - SelfHarm.

Sexual

string

The harm category for Image - Sexual.

Violence

string

The harm category for Image - Violence.

ImageData

The image can be either base64 encoded bytes or a blob URL. You can choose only one of these options. If both are provided, the request will be refused. The maximum image size is 2048 x 2048 pixels and should not exceed 4 MB, while the minimum image size is 50 x 50 pixels.

Name Type Description
blobUrl

string

The blob url of the image.

content

string

The Base64 encoding of the image.