Import an Azure OpenAI API as a REST API
APPLIES TO: All API Management tiers
This article shows how to import an Azure OpenAI API into an Azure API Management instance from its OpenAPI specification. After importing the API as a REST API, you can manage and secure it, and publish it to developers.
Prerequisites
An existing API Management instance. Create one if you haven't already.
Access granted to Azure OpenAI in the desired Azure subscription. You can apply for access to Azure OpenAI by completing the form at https://aka.ms/oai/access. Open an issue on this repo to contact us if you have an issue.
An Azure OpenAI resource with a model deployed. For more information about model deployment, see the resource deployment guide.
Make a note of the deployment ID (name). You'll need it when you test the imported API in API Management.
Download the OpenAPI specification
Download the OpenAPI specification for an endpoint that your model supports. For example, download the OpenAPI specification for the chat completion endpoint of the GPT-35-Turbo and GPT-4 models.
- In a text editor, open the specification file that you downloaded.
- In the
servers
element in the specification, substitute the name of your Azure OpenAI resource endpoint for the placeholder values in the specification. The following exampleservers
element is updated with thecontoso.openai.azure.com
resource endpoint.[...] "servers": [ { "url": "https://contoso.openai.azure.com/openai", "variables": { "endpoint": { "default": "contoso.openai.azure.com" } } } ], [...]
- Make a note of the value of the API
version
in the specification. You'll need it to test the API. Example:2023-05-15
.
Add OpenAPI specification to API Management
- In the Azure portal, navigate to your API Management instance.
- In the left menu, select APIs > + Add API.
- Under Define a new API, select OpenAPI. Enter a Display name and Name for the API and enter an API URL suffix.
- Select Create.
The API is imported and displays operations from the OpenAPI specification.
Test the new API in the portal
Operations can be called directly from the portal, which provides a convenient way for administrators to view and test the operations of an API.
Select the API you created in the previous step.
Select the Test tab.
Select an operation. The page displays fields for query parameters and fields for the headers.
Note
In the test console, API Management automatically populates an Ocp-Apim-Subscription-Key header, and configures the subscription key of the built-in all-access subscription. This key enables access to every API in the API Management instance. Optionally display the Ocp-Apim-Subscription-Key header by selecting the "eye" icon next to the HTTP Request.
Depending on the operation, enter query parameter values, header values, or a request body. Select Send.
When the test is successful, the backend responds with a successful HTTP response code and some data.
Tip
By default, the test console sends a request to API Management's CORS proxy, which forwards the request to the API Management instance, which then forwards it to the backend. This proxy uses public IP address 13.91.254.72 and can only reach public endpoints. If you want to send a request directly from the browser to the API Management service, select Bypass CORS proxy. Use this option when you want to use the test console and your API Management gateway is network-isolated or doesn't allow traffic from the CORS proxy.
To debug an API, see Tutorial: Debug your APIs using request tracing.
Important
Authentication to the OpenAI API requires an API key or a managed identity. To configure authentication using API Management policies, see Authenticate and authorize to Azure OpenAI API.
Related topics
- API import limitations
- Import an OpenAPI specification
- Import a SOAP API
- Import a SOAP API and convert to REST
- Import an App Service API
- Import a Container App API
- Import a WebSocket API
- Import a GraphQL API
- Import a GraphQL schema and set up field resolvers
- Import an Azure Function App
- Import an Azure Logic App
- Import a Service Fabric service
- Import an OData API
- Import SAP OData metadata
- Import a gRPC API
- Edit an API
Related content
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for