All Products
Search
Document Center

API Gateway:ImportHttpApi

Last Updated:Feb 05, 2026
This topic is generated by a machine translation engine without any human intervention. ALIBABA CLOUD DOES NOT GUARANTEE THE ACCURACY OF MACHINE TRANSLATED CONTENT. To request a human-translated version of this topic or provide feedback on this translation, please include it in the feedback form.

Imports HTTP APIs. You can call this operation to import OpenAPI 2.0 and OpenAPI 3.0.x definition files to create REST APIs.

Debugging

You can run this interface directly in OpenAPI Explorer, saving you the trouble of calculating signatures. After running successfully, OpenAPI Explorer can automatically generate SDK code samples.

Authorization information

The following table shows the authorization information corresponding to the API. The authorization information can be used in the Action policy element to grant a RAM user or RAM role the permissions to call this API operation. Description:

  • Operation: the value that you can use in the Action element to specify the operation on a resource.
  • Access level: the access level of each operation. The levels are read, write, and list.
  • Resource type: the type of the resource on which you can authorize the RAM user or the RAM role to perform the operation. Take note of the following items:
    • For mandatory resource types, indicate with a prefix of * .
    • If the permissions cannot be granted at the resource level, All Resources is used in the Resource type column of the operation.
  • Condition Key: the condition key that is defined by the cloud service.
  • Associated operation: other operations that the RAM user or the RAM role must have permissions to perform to complete the operation. To complete the operation, the RAM user or the RAM role must have the permissions to perform the associated operations.
OperationAccess levelResource typeCondition keyAssociated operation
apig:ImportHttpApinone
*All Resources
*
    none
none

Request syntax

POST /v1/http-apis/import HTTP/1.1

Request parameters

ParameterTypeRequiredDescriptionExample
bodyobjectNo

The request body.

specContentBase64stringNo

The Base64-encoded API definition (supports OAS 2.0/OAS 3.0 in YAML/JSON). This parameter has higher priority than the specFileUrl parameter. However, if the file size exceeds 10 MB, use the specFileUrl parameter to pass the definition.

b3BlbmFwaTogMy4wLjAKaW5mbzoKICAgIHRpdGxlOiBkZW1vCiAgICBkZXNjcmlwdGlvbjogdGhpc2lzZGVtbwogICAgdmVyc2lvbjogIiIKcGF0aHM6CiAgICAvdXNlci97dXNlcklkfToKICAgICAgICBnZXQ6CiAgICAgICAgICAgIHN1bW1hcnk6IOiOt+WPlueUqOaIt+S/oeaBrwogICAgICAgICAgICBkZXNjcmlwdGlvbjog6I635Y+W55So5oi35L+h5oGvCiAgICAgICAgICAgIG9wZXJhdGlvbklkOiBHZXRVc2VySW5mbwogICAgICAgICAgICByZXNwb25zZXM6CiAgICAgICAgICAgICAgICAiMjAwIjoKICAgICAgICAgICAgICAgICAgICBkZXNjcmlwdGlvbjog5oiQ5YqfCiAgICAgICAgICAgICAgICAgICAgY29udGVudDoKICAgICAgICAgICAgICAgICAgICAgICAgYXBwbGljYXRpb24vanNvbjtjaGFyc2V0PXV0Zi04OgogICAgICAgICAgICAgICAgICAgICAgICAgICAgc2NoZW1hOiBudWxsCnNlcnZlcnM6CiAgICAtIHVybDogaHR0cDovL2FwaS5leGFtcGxlLmNvbS92MQo=
specFileUrlstringNo

The download URL of the API definition file. Must be either a publicly accessible Object Storage Service (OSS) URL or an OSS intranet endpoint within the same region. Requires download permissions. For OSS URLs that are not publicly readable, refer to https://www.alibabacloud.com/help/en/oss/user-guide/how-to-obtain-the-url-of-a-single-object-or-the-urls-of-multiple-objects and use URLs with download permissions. Currently, only OSS URLs are supported.

https://my-bucket.oss-cn-hangzhou.aliyuncs.com/my-api/api.yaml
namestringNo

The imported API name. If not specified, a name is extracted from the API definition file. If the API name and versioning configuration already exist, this import will update the existing API definition based on the strategy field.

import-test
descriptionstringNo

The imported API description (255-byte limit). If not specified, a description is extracted from the API definition file. A maximum of 255 bytes is supported.

API for testing
versionConfigHttpApiVersionConfigNo

The API versioning configuration. If versioning is enabled, an imported API that matches both the version number and the API name of an existing API will update that API. If versioning is disabled, an imported API that matches the API name of an existing API will update it.

dryRunbooleanNo

Specifies whether to perform a precheck. If set to true, a check is performed without actual import.

false
strategystringNo

The conflict resolution strategy when the API to be imported has the same name and version as an existing one. Valid values:

  • SpecOnly: full override.
  • SpecFirst: Merge with priority on the newly imported file. New APIs are created and existing ones are updated. APIs not included in the file remain unchanged.
  • ExistFirst (default): Merge with priority on existing APIs. New APIs are created but existing ones remain unchanged. If this parameter is not specified, the ExistFirst policy takes effect.
ExistFirst
targetHttpApiIdstringNo

The target REST API ID for direct updates. If specified, the import operation will directly update the designated API instead of creating new APIs or updating existing APIs based on the name and version. Only REST APIs can be specified.

api-xxxx
resourceGroupIdstringNorg-acfm3q4zjh7fkki
specOssConfigobjectNo

The OSS configuration details.

regionIdstringNo

The region ID.

cn-hangzhou
bucketNamestringNo

The OSS bucket name.

api-1
objectKeystringNo

The full file path in OSS.

/test/swagger.json
deployConfigsarrayNo

The API deployment configuration.

HttpApiDeployConfigNo

HttpApiDeployConfig

mcpRouteIdstringNo

The MCP route ID.

xxx
gatewayIdstringNo

Gateway ID.

gw-xxx

Response parameters

ParameterTypeDescriptionExample
object

The response payload.

requestIdstring

The request ID.

CE857A85-251D-5018-8103-A38957D71E20
codestring

The status code.

Ok
messagestring

The returned message.

success
dataobject

The API information.

namestring

The API name.

import-test
httpApiIdstring

The API ID.

api-xxx
dryRunInfoobject

The dry run result.

successOperationsarray<object>

The operations that pass the dry run.

successOperationobject

The operation information.

actionstring

The action that will be performed for the operation after the dry run.

  • Create: The operation is created.
  • Update: The operation is updated.
Create
namestring

The operation name.

CreateUser
pathstring

The operation path.

/v1/users
methodstring

The HTTP method of the operation.

POST
failureOperationsarray<object>

The operations that fail the dry run.

failureOperationobject

The operation information.

pathstring

The operation path.

/v1/orders
methodstring

The HTTP method of the operation.

GET
errorMessagestring

The error message.

Missing response definition.
successComponentsarray<object>

The data structs that pass the dry run.

successComponentobject

The data struct information.

actionstring

The action that will be performed for the data struct after the dry run.

  • Create: The data struct is created.
  • Update: The data struct is updated.
Create
namestring

The data struct name.

userDTO
failureComponentsarray<object>

The data structs that fail the dry run.

failureComponentobject

The data struct information.

namestring

The data struct name.

orderDTO
errorMessagestring

The error message.

The data struct is incorrectly defined.
errorMessagesarray

The error messages. If an error message is returned, the API fails to be imported.

errorMessagestring

The error message.

OpenAPI 3.1.x is not supported.
warningMessagesarray

The alerts. If an alert is returned, specific operations or structs may fail to be imported.

warningMessagestring

The alert.

Parameter definition is incomplete for GET /v1/orders.
existHttpApiInfoHttpApiApiInfo

The existing APIs. If an existing API is returned, the import updates the existing API.

Examples

Sample success responses

JSONformat

{
  "requestId": "CE857A85-251D-5018-8103-A38957D71E20",
  "code": "Ok",
  "message": "success",
  "data": {
    "name": "import-test",
    "httpApiId": "api-xxx",
    "dryRunInfo": {
      "successOperations": [
        {
          "action": "Create",
          "name": "CreateUser",
          "path": "/v1/users",
          "method": "POST"
        }
      ],
      "failureOperations": [
        {
          "path": "/v1/orders",
          "method": "GET",
          "errorMessage": "Missing response definition.\n"
        }
      ],
      "successComponents": [
        {
          "action": "Create",
          "name": "userDTO"
        }
      ],
      "failureComponents": [
        {
          "name": "orderDTO",
          "errorMessage": "The data struct is incorrectly defined.\n"
        }
      ],
      "errorMessages": [
        "OpenAPI 3.1.x is not supported.\n"
      ],
      "warningMessages": [
        "Parameter definition is incomplete for GET /v1/orders.\n"
      ],
      "existHttpApiInfo": {
        "httpApiId": "api-xxx",
        "name": "test",
        "basePath": "/v1",
        "description": "",
        "versionInfo": {
          "enable": true,
          "scheme": "Query",
          "headerName": "my-version",
          "queryName": "myVersion",
          "version": "v1"
        },
        "ingressInfo": {
          "sourceId": "",
          "ingressClass": "",
          "watchNamespace": "",
          "environmentInfo": {
            "environmentId": ""
          },
          "k8sClusterInfo": {
            "clusterId": ""
          },
          "overrideIngressIp": true
        },
        "type": "Rest",
        "resourceGroupId": "rg-xxx",
        "enabelAuth": true,
        "authConfig": {
          "authType": "",
          "authMode": ""
        },
        "gatewayId": "",
        "modelCategory": "",
        "protocols": [
          "HTTP"
        ],
        "environments": [
          {
            "environmentId": "env-xxx",
            "backendScene": "SingleService",
            "backendType": "Service",
            "serviceConfigs": [
              {
                "gatewayServiceId": "gs-xxx",
                "name": "demo-service",
                "protocol": "HTTP",
                "port": 8080,
                "weight": 100,
                "version": "v1",
                "match": {
                  "default": true,
                  "conditions": [
                    {
                      "type": "Query",
                      "key": "color",
                      "value": "gray",
                      "operator": "equal"
                    }
                  ]
                },
                "serviceId": "svc-xxx"
              }
            ],
            "customDomains": [
              {
                "domainId": "d-xxx",
                "name": "www.example.com",
                "protocol": "HTTP"
              }
            ],
            "name": "test",
            "alias": "test",
            "gatewayInfo": {
              "gatewayId": "gw-xxx",
              "name": "test"
            },
            "deployStatus": "Deployed",
            "subDomains": [
              {
                "domainId": "d-xxx",
                "name": "www.example.com",
                "protocol": "HTTP",
                "networkType": "Internet"
              }
            ]
          }
        ],
        "aiProtocols": [
          ""
        ],
        "deployConfigs": [
          {
            "environmentId": "env-xxx",
            "backendScene": "SingleService",
            "autoDeploy": true,
            "gatewayId": "gw-xx",
            "routeBackend": {
              "scene": "Single",
              "services": [
                {
                  "serviceId": "service-cq2bmmdlhtgj***",
                  "name": "item-service",
                  "protocol": "HTTP",
                  "port": 0,
                  "weight": 49,
                  "version": "v1"
                }
              ]
            },
            "gatewayInfo": {
              "gatewayId": "",
              "name": "",
              "vpcInfo": {
                "vpcId": "",
                "name": ""
              },
              "engineVersion": ""
            },
            "mock": {
              "enable": false,
              "responseCode": 200,
              "responseContent": ""
            },
            "gatewayType": "API",
            "customDomainIds": [
              "d-xxx"
            ],
            "serviceConfigs": [
              {
                "serviceId": "svc-xxx",
                "weight": 100,
                "modelNamePattern": "qwen-*",
                "modelName": "qwen-max",
                "intentCode": "",
                "match": {
                  "default": true,
                  "conditions": [
                    {
                      "type": "Query",
                      "key": "color",
                      "value": "gray",
                      "operator": "equal"
                    }
                  ]
                }
              }
            ],
            "policyConfigs": [
              {
                "type": "AiFallback",
                "enable": true,
                "aiFallbackConfig": {
                  "serviceConfigs": [
                    {
                      "serviceId": "",
                      "targetModelName": ""
                    }
                  ]
                },
                "aiSecurityGuardConfig": {
                  "serviceAddress": "",
                  "checkRequest": true,
                  "checkResponse": true,
                  "checkRequestImage": true,
                  "checkResponseImage": true,
                  "requestCheckService": "",
                  "responseCheckService": "",
                  "requestImageCheckService": "",
                  "responseImageCheckService": "",
                  "riskAlertLevel": "",
                  "riskConfig": [
                    {
                      "type": "",
                      "level": "",
                      "consumerRules": {
                        "pattern": "",
                        "matchType": ""
                      }
                    }
                  ],
                  "bufferLimit": 0,
                  "consumerRequestCheckService": [
                    {
                      "name": "",
                      "requestCheckService": "",
                      "requestImageCheckService": "",
                      "matchType": "",
                      "modalityType": ""
                    }
                  ],
                  "consumerResponseCheckService": [
                    {
                      "name": "",
                      "responseCheckService": "",
                      "responseImageCheckService": "",
                      "matchType": "",
                      "modalityType": ""
                    }
                  ],
                  "consumerRiskLevel": [
                    {
                      "name": "",
                      "matchType": "",
                      "type": "",
                      "level": ""
                    }
                  ]
                },
                "aiTokenRateLimitConfig": {
                  "rules": [
                    {
                      "limitType": "",
                      "matchKey": "",
                      "matchType": "",
                      "matchValue": "",
                      "limitMode": "",
                      "limitValue": 0
                    }
                  ],
                  "globalRules": [
                    {
                      "limitType": "",
                      "matchKey": "",
                      "matchType": "",
                      "matchValue": "",
                      "limitMode": "",
                      "limitValue": 0
                    }
                  ],
                  "enableGlobalRules": true
                }
              }
            ],
            "customDomainInfos": [
              {
                "domainId": "",
                "name": "",
                "protocol": ""
              }
            ],
            "subDomains": [
              {
                "domainId": "",
                "name": "",
                "protocol": "",
                "networkType": ""
              }
            ]
          }
        ],
        "deployCntMap": {
          "key": {
            "deployedCnt": 0,
            "Cnt": 0
          }
        },
        "agentProtocols": [
          ""
        ]
      }
    }
  }
}

Error codes

For a list of error codes, visit the Service error codes.

Change history

Change timeSummary of changesOperation
2025-08-13The internal configuration of the API is changed, but the call is not affectedView Change Details
2025-08-12The internal configuration of the API is changed, but the call is not affectedView Change Details
2025-04-25The internal configuration of the API is changed, but the call is not affectedView Change Details