Skip to content

Commit 17f6328

Browse files
authored
Merge pull request #300709 from dlepow/apimgem
[APIM] Add Gemini LLM example
2 parents 8807233 + ceca506 commit 17f6328

File tree

5 files changed

+123
-19
lines changed

5 files changed

+123
-19
lines changed

articles/api-management/TOC.yml

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -236,18 +236,22 @@
236236
items:
237237
- name: AI gateway capabilities in API Management
238238
href: genai-gateway-capabilities.md
239-
- name: Import Azure AI Foundry API
240-
href: azure-ai-foundry-api.md
241-
- name: Import Azure OpenAI API
242-
href: azure-openai-api-from-specification.md
243-
- name: Import OpenAI-compatible LLM API
244-
href: openai-compatible-llm-api.md
245-
- name: Authenticate and authorize to Azure OpenAI
246-
href: api-management-authenticate-authorize-azure-openai.md
239+
- name: Import LLM APIs
240+
items:
241+
- name: Import Azure AI Foundry API
242+
href: azure-ai-foundry-api.md
243+
- name: Import Azure OpenAI API
244+
href: azure-openai-api-from-specification.md
245+
- name: Import language model API
246+
href: openai-compatible-llm-api.md
247+
- name: Import Google Gemini API
248+
href: openai-compatible-google-gemini-api.md
247249
- name: Expose REST API as MCP server
248250
href: export-rest-mcp-server.md
249251
- name: Semantic caching for Azure OpenAI API requests
250252
href: azure-openai-enable-semantic-caching.md
253+
- name: Authenticate and authorize to Azure OpenAI
254+
href: api-management-authenticate-authorize-azure-openai.md
251255
- name: Protect Azure OpenAI keys
252256
href: /semantic-kernel/deploy/use-ai-apis-with-api-management?toc=%2Fazure%2Fapi-management%2Ftoc.json&bc=/azure/api-management/breadcrumb/toc.json
253257
- name: Manage APIs with policies
@@ -689,4 +693,4 @@
689693
- name: Stack Overflow
690694
href: https://stackoverflow.com/questions/tagged/azure-api-management
691695
- name: aka.ms/apimlove
692-
href: https://aka.ms/apimlove
696+
href: https://aka.ms/apimlove
132 KB
Loading
55.3 KB
Loading
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
---
2+
title: Import OpenAI-Compatible Google Gemini API - Azure API Management
3+
description: How to import an OpenAI-compatible Google Gemini model as a REST API in Azure API Management and manage a chat completions endpoint
4+
ms.service: azure-api-management
5+
author: dlepow
6+
ms.author: danlep
7+
ms.topic: how-to
8+
ms.date: 07/06/2025
9+
ms.collection: ce-skilling-ai-copilot
10+
ms.custom: template-how-to
11+
---
12+
13+
# Import an OpenAI-compatible Google Gemini API
14+
15+
[!INCLUDE [api-management-availability-all-tiers](../../includes/api-management-availability-all-tiers.md)]
16+
17+
This article shows you how to import an OpenAI-compatible Google Gemini API to access models such as `gemini-2.0-flash`. For these models, Azure API Management can manage an OpenAI-compatible chat completions endpoint.
18+
19+
Learn more about managing AI APIs in API Management:
20+
21+
* [AI gateway capabilities in Azure API Management](genai-gateway-capabilities.md)
22+
* [Import a language model API](openai-compatible-llm-api.md)
23+
24+
## Prerequisites
25+
26+
- An existing API Management instance. [Create one if you haven't already](get-started-create-service-instance.md).
27+
- An API key for the Gemini API. If you don't have one, create it at [Google AI Studio](https://aistudio.google.com/apikey) and store it in a safe location.
28+
29+
30+
## Import an OpenAI-compatible Gemini API using the portal
31+
32+
1. In the [Azure portal](https://portal.azure.com), navigate to your API Management instance.
33+
1. In the left menu, under **APIs**, select **APIs** > **+ Add API**.
34+
1. Under **Define a new API**, select **Language Model API**.
35+
36+
:::image type="content" source="media/openai-compatible-llm-api/openai-api.png" alt-text="Screenshot of creating a passthrough language model API in the portal." :::
37+
1. On the **Configure API** tab:
38+
1. Enter a **Display name** and optional **Description** for the API.
39+
1. In **URL**, enter the following base URL from the [Gemini OpenAI compatibility documentation](https://ai.google.dev/gemini-api/docs/openai):
40+
`https://generativelanguage.googleapis.com/v1beta/openai`
41+
42+
1. In **Path**, append a path that your API Management instance uses to route requests to the Gemini API endpoints.
43+
1. In **Type**, select **Create OpenAI API**.
44+
1. In **Access key**, enter the following:
45+
1. **Header name**: *Authorization*.
46+
1. **Header value (key)**: `Bearer` followed by your API key for the Gemini API.
47+
48+
:::image type="content" source="media/openai-compatible-google-gemini-api/gemini-import.png" alt-text="Screenshot of importing a Gemini LLM API in the portal.":::
49+
50+
1. On the remaining tabs, optionally configure policies to manage token consumption, semantic caching, and AI content safety. For details, see [Import a language model API](openai-compatible-llm-api.md).
51+
1. Select **Review**.
52+
1. After settings are validated, select **Create**.
53+
54+
API Management creates the API and configures the following:
55+
56+
* A [backend](backends.md) resource and a [set-backend-service](set-backend-service-policy.md) policy that direct API requests to the Google Gemini endpoint.
57+
* Access to the LLM backend using the Gemini API key you provided. The key is protected as a secret [named value](api-management-howto-properties.md) in API Management.
58+
* (optionally) Policies to help you monitor and manage the API.
59+
60+
### Test Gemini model
61+
62+
After importing the API, you can test the chat completions endpoint for the API.
63+
64+
1. Select the API that you created in the previous step.
65+
1. Select the **Test** tab.
66+
1. Select the `POST Creates a model response for the given chat conversation` operation, which is a `POST` request to the `/chat/completions` endpoint.
67+
1. In the **Request body** section, enter the following JSON to specify the model and an example prompt. In this example, the `gemini-2.0-flash` model is used.
68+
69+
```json
70+
{
71+
"model": "gemini-2.0-flash",
72+
"messages": [
73+
{
74+
"role": "system",
75+
"content": "You are a helpful assistant"
76+
},
77+
{
78+
"role": "user",
79+
"content": "How are you?"
80+
}
81+
],
82+
"max_tokens": 50
83+
}
84+
```
85+
86+
When the test is successful, the backend responds with a successful HTTP response code and some data. Appended to the response is token usage data to help you monitor and manage your language model token consumption.
87+
88+
:::image type="content" source="media/openai-compatible-google-gemini-api/gemini-test.png" alt-text="Screenshot of testing a Gemini LLM API in the portal.":::
89+
90+
## Related content
91+
92+
* [AI gateway capabilities in Azure API Management](genai-gateway-capabilities.md)

articles/api-management/openai-compatible-llm-api.md

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
---
2-
title: Import OpenAI-Compatible Language Model API - Azure API Management
3-
description: How to import an OpenAI-compatible language model or a non-Azure-provided AI model as a REST API in Azure API Management.
2+
title: Import Language Model API - Azure API Management
3+
description: How to import an OpenAI-compatible language model or a non-OpenAI-compatible AI model as a REST API in Azure API Management.
44
ms.service: azure-api-management
55
author: dlepow
66
ms.author: danlep
77
ms.topic: how-to
8-
ms.date: 05/15/2025
8+
ms.date: 07/06/2025
99
ms.update-cycle: 180-days
1010
ms.collection: ce-skilling-ai-copilot
11-
ms.custom: template-how-to, build-2024
11+
ms.custom: template-how-to
1212
---
1313

14-
# Import an OpenAI-compatible language model API
14+
# Import a language model API
1515

1616
[!INCLUDE [api-management-availability-all-tiers](../../includes/api-management-availability-all-tiers.md)]
1717

18-
You can import OpenAI-compatible language model endpoints to your API Management instance as APIs. For example, you might want to manage an LLM that you self-host, or that's hosted on an inference provider other than Azure AI services. Use AI gateway policies and other capabilities in API Management to simplify integration, improve observability, and enhance control over the model endpoints.
18+
You can import OpenAI-compatible language model endpoints to your API Management instance as APIs. You can also import language models that aren't compatible with OpenAI as passthrough APIs, which forward requests directly to the backend endpoints. For example, you might want to manage an LLM that you self-host, or that's hosted on an inference provider other than Azure AI services. Use AI gateway policies and other capabilities in API Management to simplify integration, improve observability, and enhance control over the model endpoints.
1919

2020
Learn more about managing AI APIs in API Management:
2121

22-
* [Generative AI gateway capabilities in Azure API Management](genai-gateway-capabilities.md)
22+
* [AI gateway capabilities in Azure API Management](genai-gateway-capabilities.md)
2323

2424
## Language model API types
2525

2626
API Management supports two types of language model APIs for this scenario. Choose the option suitable for your model deployment. The option determines how clients call the API and how the API Management instance routes requests to the AI service.
2727

28-
* **OpenAI-compatible** - Language model endpoints that are compatible with OpenAI's API. Examples include certain models exposed by inference providers such as [Hugging Face Text Generation Inference (TGI)](https://huggingface.co/docs/text-generation-inference/en/index).
28+
* **OpenAI-compatible** - Language model endpoints that are compatible with OpenAI's API. Examples include certain models exposed by inference providers such as [Hugging Face Text Generation Inference (TGI)](https://huggingface.co/docs/text-generation-inference/en/index) and [Google Gemini API](openai-compatible-google-gemini-api.md).
2929

30-
API Management configures an OpenAI-compatible chat completions endpoint.
30+
For an OpenAI-compatible LLM, API Management configures a chat completions endpoint.
3131

3232
* **Passthrough** - Other language model endpoints that aren't compatible with OpenAI's API. Examples include models deployed in [Amazon Bedrock](https://docs.aws.amazon.com/bedrock/latest/userguide/what-is-bedrock.html) or other providers.
3333

@@ -41,6 +41,11 @@ API Management supports two types of language model APIs for this scenario. Choo
4141

4242
## Import language model API using the portal
4343

44+
When you import the LLM API in the portal, API Management automatically configures:
45+
46+
* A [backend](backends.md) resource and a [set-backend-service](set-backend-service-policy.md) policy that direct API requests to the LLM endpoint.
47+
* (optionally) Access to the LLM backend using an access key you provide. The key is protected as a secret [named value](api-management-howto-properties.md) in API Management.
48+
* (optionally) Policies to help you monitor and manage the API.
4449

4550
To import a language model API to API Management:
4651

@@ -71,6 +76,8 @@ To import a language model API to API Management:
7176
1. Select **Review**.
7277
1. After settings are validated, select **Create**.
7378

79+
API Management creates the API, and configures operations for the LLM endpoints. By default, the API requires an API Management subscription.
80+
7481
## Test the LLM API
7582

7683
To ensure that your LLM API is working as expected, test it in the API Management test console.
@@ -85,5 +92,6 @@ To ensure that your LLM API is working as expected, test it in the API Managemen
8592

8693
When the test is successful, the backend responds with a successful HTTP response code and some data. Appended to the response is token usage data to help you monitor and manage your language model token consumption.
8794

95+
## Related content
8896

89-
[!INCLUDE [api-management-define-api-topics.md](../../includes/api-management-define-api-topics.md)]
97+
* [AI gateway capabilities in Azure API Management](genai-gateway-capabilities.md)

0 commit comments

Comments
 (0)