Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 44 additions & 6 deletions docs/agents/models/apigee.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@ Apigee proxy, you immediately gain enterprise-grade capabilities:

- **Monitoring & Visibility:** Get granular monitoring, analysis, and auditing of all your AI requests.

!!! note
The `ApigeeLLM` wrapper is designed for use with Agent Platform
and the Gemini API (generateContent). We are continually expanding support for
other models and interfaces. For OpenAI compatible models, including self-hosted or
other providers, use the `CompletionsHTTPClient` to route traffic through your Apigee proxy.

The `ApigeeLLM` wrapper is currently designed for use with Agent Platform
and the Gemini API (generateContent). We are continually expanding support for
other models and interfaces.

## Example implementation
## Implementation example

Integrate Apigee's governance into your agent's workflow by instantiating the
`ApigeeLlm` wrapper object and pass it to an `LlmAgent` or other agent type.
Expand Down Expand Up @@ -84,3 +83,42 @@ Apigee first, where all necessary policies (security, rate limiting, logging)
are executed before the request is securely forwarded to the underlying AI model
endpoint. For a full code example using the Apigee proxy, see
[Hello World Apigee LLM](https://github.com/google/adk-python/tree/main/contributing/samples/models/hello_world_apigeellm).

## Compatibility with OpenAI

The `CompletionsHTTPClient` is a generic HTTP client designed for compatibility with the OpenAI API format. It allows you to route requests through proxies (such as Apigee) that expect standard OpenAI-compatible `/chat/completions` endpoints, rather than native Gemini or Vertex AI protocols. This client handles:

- **Payload construction**: Converts LlmRequest objects into the format required by OpenAI-compatible APIs.
- **Response handling**: Manages streaming and non-streaming responses from the proxy.
- **Reliability**: Uses `tenacity` for built-in retry logic.
- **Normalization**: Parses responses and streaming chunks into the standard format expected by the rest of the ADK framework.

### Implementation example

```python

import asyncio
Comment thread
zyantw marked this conversation as resolved.
from google.adk.models.apigee_llm import CompletionsHTTPClient
from google.adk.models.llm_request import LlmRequest
from google.genai import types

async def test_client():
# 1. Initialize the client
client = CompletionsHTTPClient(
base_url="https://your-apigee-proxy-url.com/v1",
headers={"Authorization": "Bearer YOUR_API_KEY"}
)

# 2. Construct a minimal request
request = LlmRequest(
model="gpt-4o", # Replace with your target model ID
contents=[types.Content(role="user", parts=[types.Part.from_text(text="Hello!")])]
)

# 3. Execute a non-streaming generation
async for response in client.generate_content_async(request, stream=False):
print(f"Response: {response.text}")

if __name__ == "__main__":
asyncio.run(test_client())
```
Loading