Skip to content

Commit 968e1f0

Browse files
Restrict managed OpenAI LLM models in AgentKit
1 parent 434c8af commit 968e1f0

4 files changed

Lines changed: 19 additions & 2 deletions

File tree

docs/concepts/vendors.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Used with `agent.with_llm()` for the cascading flow (ASR → LLM → TTS).
2222
| Class | Provider | Required Parameters |
2323
|---|---|---|
2424
| `OpenAI` | OpenAI | `model` for Agora-managed models; `api_key`, `base_url`, `model` for BYOK |
25-
| `AzureOpenAI` | Azure OpenAI | `api_key`, `endpoint`, `deployment_name` |
25+
| `AzureOpenAI` | Azure OpenAI | `api_key`, `model`, `endpoint`, `deployment_name` |
2626
| `Anthropic` | Anthropic | `api_key`, `model`, `url`, `headers`, `max_tokens` |
2727
| `Gemini` | Google Gemini | `api_key`, `model` |
2828
| `Groq` | Groq | `api_key`, `model`, `base_url` |

docs/reference/vendors.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ llm = OpenAI(api_key='your-key', base_url='https://api.openai.com/v1/chat/comple
5151
| Parameter | Type | Required | Default | Description |
5252
|---|---|---|---|---|
5353
| `api_key` | `str` | Yes || Azure OpenAI API key |
54+
| `model` | `str` | Yes || Deployment's base model name. Emitted as `params.model`. |
5455
| `endpoint` | `str` | Yes || Azure endpoint URL |
5556
| `deployment_name` | `str` | Yes || Azure deployment name |
5657
| `api_version` | `str` | No | `2024-08-01-preview` | Azure API version |
@@ -73,6 +74,7 @@ from agora_agent import AzureOpenAI
7374

7475
llm = AzureOpenAI(
7576
api_key='your-azure-key',
77+
model='gpt-4o-mini',
7678
endpoint='https://your-resource.openai.azure.com',
7779
deployment_name='gpt-4o-mini',
7880
)
@@ -144,7 +146,7 @@ The SDK also includes named helpers for the remaining Agora-supported LLM provid
144146

145147
| Class | Provider | Key parameters |
146148
|---|---|---|
147-
| `Groq` | Groq | `api_key`, `model`, `base_url?` |
149+
| `Groq` | Groq | `api_key`, `model`, `base_url` |
148150
| `VertexAILLM` | Google Vertex AI | `api_key`, `model`, `project_id`, `location`, `url?` |
149151
| `AmazonBedrock` | Amazon Bedrock | `access_key`, `secret_key`, `region`, `model` |
150152
| `Dify` | Dify | `api_key`, `url`, `model`, `user?`, `conversation_id?` |

src/agora_agent/agentkit/vendors/llm.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from .base import BaseLLM
66

77
LlmGreetingConfigs = Dict[str, Any]
8+
_OPENAI_MANAGED_MODELS = {"gpt-4o-mini", "gpt-4.1-mini", "gpt-5-nano", "gpt-5-mini"}
89

910

1011
def _ensure_mcp_transport(servers: List[Dict[str, Any]]) -> List[Dict[str, Any]]:
@@ -55,6 +56,10 @@ def _validate_byok_params(self) -> "OpenAIOptions":
5556
raise ValueError("OpenAI requires base_url when api_key is set")
5657
if self.api_key is None and self.base_url is not None:
5758
raise ValueError("OpenAI base_url is only valid when api_key is set")
59+
if self.api_key is None and self.model.strip().lower() not in _OPENAI_MANAGED_MODELS:
60+
raise ValueError("OpenAI requires api_key unless using a supported Agora-managed model")
61+
if self.api_key is None and self.vendor is not None:
62+
raise ValueError("OpenAI Agora-managed mode does not allow vendor")
5863
return self
5964

6065
class OpenAI(BaseLLM):

tests/custom/test_llm_vendors.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,13 @@ def test_llm_vendors_reject_missing_required_models() -> None:
122122

123123
with pytest.raises(Exception, match="model"):
124124
AmazonBedrock(access_key="aws-access", secret_key="aws-secret", region="us-east-1")
125+
126+
127+
def test_openai_managed_mode_is_restricted_to_supported_models() -> None:
128+
assert OpenAI(model="gpt-5-mini").to_config()["params"]["model"] == "gpt-5-mini"
129+
130+
with pytest.raises(Exception, match="api_key"):
131+
OpenAI(model="gpt-4o")
132+
133+
with pytest.raises(Exception, match="does not allow vendor"):
134+
OpenAI(model="gpt-5-mini", vendor="custom")

0 commit comments

Comments
 (0)