Skip to content

Personal AI, On Personal Devices

Python

feat(engine): add Atlas Cloud as a cloud inference provider (#988)

nb21347979f277772
diff --git a/docs/getting-started/configuration.md b/docs/getting-started/configuration.md
index 6655b436..45aaebf1 100644
--- a/docs/getting-started/configuration.md
+++ b/docs/getting-started/configuration.md
@@ -1127,12 +1127,16 @@ OpenJarvis respects the following environment variables:
| `ANTHROPIC_API_KEY` | API key for Anthropic cloud inference. Required for the `cloud` engine with Claude models. |
| `GOOGLE_API_KEY` | API key for Google Gemini inference. Required for the `google` engine. |
| `MINIMAX_API_KEY` | API key for MiniMax cloud inference. Required for the `cloud` engine with MiniMax models (MiniMax-M3, MiniMax-M2.7, MiniMax-M2.7-highspeed, MiniMax-M2.5, MiniMax-M2.5-highspeed). |
+| `ATLASCLOUD_API_KEY` | API key for [Atlas Cloud](https://www.atlascloud.ai) inference. Required for the `cloud` engine with `atlascloud/`-prefixed models (e.g. `atlascloud/openai/gpt-4.1-mini`, `atlascloud/deepseek-ai/deepseek-v3.2`). Atlas Cloud is an OpenAI-compatible aggregator — `GET https://api.atlascloud.ai/v1/models` lists every routable ID. |
| `TAVILY_API_KEY` | API key for the Tavily web search engine. Optional — when set, `auto` engine selection prefers Tavily. |
| `YOUDOTCOM_API_KEY` | API key for the You.com web search engine. Optional — raises the keyless free-tier limits and enables You.com Contents extraction for URL queries. |
| `SERPLY_API_KEY` | API key for the Serply web search engine, which proxies Google. Optional. When set and no other search key is, `auto` engine selection prefers Serply over the keyless tier. Keys: [serply.io](https://serply.io). |
| `SERPLY_PROXY_LOCATION` | Two-letter country code asking Serply for that country's Google result set, for example `DE`. Optional. Unset means the API answers from its own default region. See [serply.io/docs](https://serply.io/docs). |
| `OPENJARVIS_WEB_SEARCH_ENGINE` | Web search engine for the `web_search` tool: `auto` (default), `youcom`, `tavily`, `serply`, or `duckduckgo`. |
+In the desktop app, you can save `ATLASCLOUD_API_KEY` in **Cloud Models** or
+**Settings → API Keys** instead of setting an environment variable.
+
## Next Steps
- [Quick Start](quickstart.md) — Run your first query
diff --git a/frontend/src-tauri/src/lib.rs b/frontend/src-tauri/src/lib.rs
index 54ea7d5b..3c5d6686 100644
--- a/frontend/src-tauri/src/lib.rs
+++ b/frontend/src-tauri/src/lib.rs
@@ -2113,6 +2113,7 @@ const MANAGED_CLOUD_KEY_NAMES: &[&str] = &[
"GEMINI_API_KEY",
"GOOGLE_API_KEY",
"OPENROUTER_API_KEY",
+ "ATLASCLOUD_API_KEY",
"MINIMAX_API_KEY",
"TAVILY_API_KEY",
];
@@ -3448,9 +3449,10 @@ mod tests {
use super::{
boot_plan, default_local_model, discard_pending_inference_setup_at,
format_extension_import_failure, format_missing_rust_toolchain, format_port_unavailable,
- format_uv_sync_failure, format_uv_sync_spawn_error, matching_installed_model,
- model_names_match, normalize_host, parse_configured_inference_config,
- parse_ollama_model_names, persist_confirmed_inference_config_at, preferred_installed_model,
+ format_uv_sync_failure, format_uv_sync_spawn_error, managed_cloud_key_names,
+ matching_installed_model, model_names_match, normalize_host,
+ parse_configured_inference_config, parse_ollama_model_names,
+ persist_confirmed_inference_config_at, preferred_installed_model,
project_root_near_executable, reload_cloud_keys_for_owned_backend_at,
should_persist_resolved_model, spawn_owned_child, stage_pending_inference_config_at,
startup_installed_model, upsert_engine_host, uv_sync_stderr_tail, BackendManager,
@@ -3461,6 +3463,11 @@ mod tests {
use std::path::Path;
use std::sync::Mutex as StdMutex;
+ #[test]
+ fn atlas_cloud_key_is_loaded_with_managed_desktop_keys() {
+ assert!(managed_cloud_key_names().contains(&"ATLASCLOUD_API_KEY".to_string()));
+ }
+
#[derive(Default)]
struct MemoryCredentialStore {
values: StdMutex<HashMap<String, String>>,
diff --git a/frontend/src/components/CommandPalette.tsx b/frontend/src/components/CommandPalette.tsx
index 971c6780..cb252527 100644
--- a/frontend/src/components/CommandPalette.tsx
+++ b/frontend/src/components/CommandPalette.tsx
@@ -71,6 +71,15 @@ const CLOUD_PROVIDERS: CloudProvider[] = [
{ id: 'openrouter/deepseek/deepseek-r1', desc: 'DeepSeek R1 via OpenRouter' },
],
},
+ {
+ name: 'Atlas Cloud',
+ envKey: 'ATLASCLOUD_API_KEY',
+ models: [
+ { id: 'atlascloud/openai/gpt-4.1-mini', desc: 'GPT-4.1 Mini via Atlas Cloud' },
+ { id: 'atlascloud/deepseek-ai/deepseek-v3.2', desc: 'DeepSeek V3.2 via Atlas Cloud' },
+ { id: 'atlascloud/Qwen/Qwen3-235B-A22B-Instruct-2507', desc: 'Qwen3 235B via Atlas Cloud' },
+ ],
+ },
];
type Tab = 'installed' | 'catalogue' | 'cloud';
diff --git a/frontend/src/pages/SettingsPage.cloud-providers.test.tsx b/frontend/src/pages/SettingsPage.cloud-providers.test.tsx
new file mode 100644
index 00000000..2e35fe7f
--- /dev/null
+++ b/frontend/src/pages/SettingsPage.cloud-providers.test.tsx
@@ -0,0 +1,17 @@
+import { renderToStaticMarkup } from 'react-dom/server';
+import { describe, expect, it, vi } from 'vitest';
+
+describe('desktop cloud provider settings', () => {
+ it('offers Atlas Cloud key storage alongside its provider status', async () => {
+ vi.stubGlobal('localStorage', { getItem: () => null });
+ vi.stubGlobal('window', { __TAURI_INTERNALS__: {} });
+ const { SettingsPage } = await import('./SettingsPage');
+ const html = renderToStaticMarkup(<SettingsPage />);
+
+ expect(html).toContain('Atlas Cloud');
+ const atlasKeyInput = html.match(/<input[^>]*placeholder="Atlas Cloud API key"[^>]*>/)?.[0];
+ expect(atlasKeyInput).toBeDefined();
+ expect(atlasKeyInput).not.toContain('disabled');
+ vi.unstubAllGlobals();
+ });
+});
diff --git a/frontend/src/pages/SettingsPage.tsx b/frontend/src/pages/SettingsPage.tsx
index 2437b299..b730b1a9 100644
--- a/frontend/src/pages/SettingsPage.tsx
+++ b/frontend/src/pages/SettingsPage.tsx
@@ -551,6 +551,7 @@ export function SettingsPage() {
<CloudProviderStatus label="Anthropic" keyName="ANTHROPIC_API_KEY" />
<CloudProviderStatus label="Google" keyName="GEMINI_API_KEY" />
<CloudProviderStatus label="OpenRouter" keyName="OPENROUTER_API_KEY" />
+ <CloudProviderStatus label="Atlas Cloud" keyName="ATLASCLOUD_API_KEY" />
</div>
</SettingRow>
</Section>
@@ -569,6 +570,9 @@ export function SettingsPage() {
<SettingRow label="OpenRouter" description="Multi-provider routing">
<ApiKeyInput keyName="OPENROUTER_API_KEY" placeholder="sk-or-..." />
</SettingRow>
+ <SettingRow label="Atlas Cloud" description="Models routed through Atlas Cloud">
+ <ApiKeyInput keyName="ATLASCLOUD_API_KEY" placeholder="Atlas Cloud API key" />
+ </SettingRow>
</Section>
{/* Tools */}
diff --git a/src/openjarvis/engine/cloud.py b/src/openjarvis/engine/cloud.py
index 6c8392af..5dae86c9 100644
--- a/src/openjarvis/engine/cloud.py
+++ b/src/openjarvis/engine/cloud.py
@@ -1,6 +1,6 @@
"""Cloud inference engine.
-OpenAI, Anthropic, Google, MiniMax, and DeepSeek API backends.
+OpenAI, Anthropic, Google, MiniMax, DeepSeek, and Atlas Cloud API backends.
"""
from __future__ import annotations
@@ -55,6 +55,19 @@ PRICING: Dict[str, tuple[float, float]] = {
"MiniMax-M2.5-highspeed": (0.60, 2.40),
"deepseek-v4-flash": (0.27, 1.10),
"deepseek-v4-pro": (0.55, 2.19),
+ # Atlas Cloud — an aggregator, so keys carry the "atlascloud/" routing
+ # prefix (same convention as OpenRouter below). Rates are USD per 1M
+ # tokens, read from the gateway's own catalog: GET
+ # https://api.atlascloud.ai/v1/models returns pricing.prompt /
+ # pricing.completion in USD *per token*; multiply by 1e6.
+ "atlascloud/openai/gpt-4.1-mini": (0.40, 1.60),
+ "atlascloud/openai/gpt-5.4-mini": (0.75, 4.50),
+ "atlascloud/deepseek-ai/deepseek-v3.2": (0.26, 0.38),
+ "atlascloud/Qwen/Qwen3-235B-A22B-Instruct-2507": (0.20, 0.88),
+ "atlascloud/qwen/qwen3.5-35b-a3b": (0.225, 1.80),
+ "atlascloud/zai-org/GLM-4.6": (0.60, 2.20),
+ "atlascloud/moonshotai/kimi-k2.5": (0.49, 2.50),
+ "atlascloud/minimaxai/minimax-m2.5": (0.295, 1.20),
}
_MINIMAX_M3_LONG_CONTEXT_THRESHOLD = 512_000
@@ -111,6 +124,23 @@ _OPENROUTER_POPULAR = [
"openrouter/qwen/qwen3-235b-a22b",
]
+# Atlas Cloud models — prefixed with "atlascloud/" so they can be identified.
+# Atlas Cloud is an OpenAI-compatible aggregator whose own model IDs are
+# already "vendor/model", so the prefix is what keeps
+# "atlascloud/anthropic/claude-*" from being routed to the Anthropic SDK.
+# The gateway serves many more than these — GET /v1/models lists what is
+# currently routable, and any ID from there works as "atlascloud/<id>".
+_ATLASCLOUD_POPULAR = [
+ "atlascloud/openai/gpt-4.1-mini",
+ "atlascloud/openai/gpt-5.4-mini",
+ "atlascloud/deepseek-ai/deepseek-v3.2",
+ "atlascloud/Qwen/Qwen3-235B-A22B-Instruct-2507",
+ "atlascloud/qwen/qwen3.5-35b-a3b",
+ "atlascloud/zai-org/GLM-4.6",
+ "atlascloud/moonshotai/kimi-k2.5",
+ "atlascloud/minimaxai/minimax-m2.5",
+]
+
# Codex models — prefixed with "codex/" for ChatGPT Plus/Pro subscribers.
# Uses the Responses API at chatgpt.com, not the standard OpenAI API.
_CODEX_MODELS = [
@@ -134,16 +164,30 @@ def _is_openrouter_model(model: str) -> bool:
return model.startswith("openrouter/")
+def _is_atlascloud_model(model: str) -> bool:
+ return model.startswith("atlascloud/")
+
+
def _is_codex_model(model: str) -> bool:
return model.startswith("codex/")
def _is_anthropic_model(model: str) -> bool:
- return "claude" in model.lower() and not _is_openrouter_model(model)
+ # Aggregator-prefixed IDs are excluded: "atlascloud/anthropic/claude-*"
+ # contains "claude" but must go to the aggregator, not the Anthropic SDK.
+ return (
+ "claude" in model.lower()
+ and not _is_openrouter_model(model)
+ and not _is_atlascloud_model(model)
+ )
def _is_google_model(model: str) -> bool:
- return "gemini" in model.lower() and not _is_openrouter_model(model)
+ return (
+ "gemini" in model.lower()
+ and not _is_openrouter_model(model)
+ and not _is_atlascloud_model(model)
+ )
# Positive prefix predicate for genuine OpenAI models. Kept in sync with
@@ -344,7 +388,8 @@ def _convert_tools_to_google(
@EngineRegistry.register("cloud")
class CloudEngine(InferenceEngine):
- """Cloud inference via OpenAI, Anthropic, Google, MiniMax, and DeepSeek SDKs."""
+ """Cloud inference via OpenAI, Anthropic, Google, MiniMax, DeepSeek, and
+ Atlas Cloud SDKs."""
engine_id = "cloud"
is_cloud = True
@@ -354,6 +399,7 @@ class CloudEngine(InferenceEngine):
self._anthropic_client: Any = None
self._google_client: Any = None
self._openrouter_client: Any = None
+ self._atlascloud_client: Any = None
self._minimax_client: Any = None
self._deepseek_client: Any = None
self._codex_client: Any = None
@@ -397,6 +443,17 @@ class CloudEngine(InferenceEngine):
)
except ImportError:
pass
+ atlascloud_key = os.environ.get("ATLASCLOUD_API_KEY")
+ if atlascloud_key:
+ try:
+ import openai
+
+ self._atlascloud_client = openai.OpenAI(
+ base_url="https://api.atlascloud.ai/v1",
+ api_key=atlascloud_key,
+ )
+ except ImportError:
+ pass
minimax_key = os.environ.get("MINIMAX_API_KEY")
if minimax_key:
try:
@@ -1019,6 +1076,73 @@ class CloudEngine(InferenceEngine):
]
return result
+ def _generate_atlascloud(
+ self,
+ messages: Sequence[Message],
+ *,
+ model: str,
+ temperature: float,
+ max_tokens: int,
+ **kwargs: Any,
+ ) -> Dict[str, Any]:
+ if self._atlascloud_client is None:
+ raise EngineConnectionError(
+ "Atlas Cloud client not available — set ATLASCLOUD_API_KEY"
+ )
+ # Strip the "atlascloud/" prefix to get the gateway's own model ID.
+ actual_model = model.removeprefix("atlascloud/")
+ create_kwargs: Dict[str, Any] = {
+ "model": actual_model,
+ "messages": messages_to_dicts(messages),
+ "max_tokens": max_tokens,
+ "temperature": temperature,
+ }
+ # Atlas Cloud is OpenAI-compatible: response_format, tools and
+ # tool_choice all pass straight through.
+ response_format = kwargs.pop("response_format", None)
+ if response_format is not None:
+ create_kwargs["response_format"] = response_format
+ tools = kwargs.pop("tools", None)
+ if tools:
+ create_kwargs["tools"] = tools
+ tool_choice = kwargs.pop("tool_choice", None)
+ if tool_choice is not None:
+ create_kwargs["tool_choice"] = tool_choice
+ t0 = time.monotonic()
+ resp = self._atlascloud_client.chat.completions.create(**create_kwargs)
+ elapsed = time.monotonic() - t0
+ choice = resp.choices[0]
+ usage = resp.usage
+ prompt_tokens = usage.prompt_tokens if usage else 0
+ completion_tokens = usage.completion_tokens if usage else 0
+ result: Dict[str, Any] = {
+ "content": choice.message.content or "",
+ "usage": {
+ "prompt_tokens": prompt_tokens,
+ "completion_tokens": completion_tokens,
+ "total_tokens": (usage.total_tokens if usage else 0),
+ },
+ "model": resp.model,
+ "finish_reason": choice.finish_reason or "stop",
+ # Cost is keyed on the prefixed ID so PRICING stays unambiguous
+ # between "atlascloud/minimaxai/minimax-m2.5" and MiniMax direct.
+ "cost_usd": estimate_cost(model, prompt_tokens, completion_tokens),
+ "ttft": elapsed,
+ }
+ if getattr(choice.message, "tool_calls", None):
+ result["tool_calls"] = [
+ {
+ "id": tc.id,
+ "type": tc.type,
+ "function": {
+ "name": tc.function.name,
+ "arguments": tc.function.arguments,
+ },
+ }
+ for tc in choice.message.tool_calls
+ ]
+ return result
+
def _generate_minimax(
self,
messages: Sequence[Message],
@@ -1141,6 +1265,8 @@ class CloudEngine(InferenceEngine):
return self._generate_codex(messages, **kw)
if _is_openrouter_model(model):
return self._generate_openrouter(messages, **kw)
+ if _is_atlascloud_model(model):
+ return self._generate_atlascloud(messages, **kw)
if _is_minimax_model(model):
return self._generate_minimax(messages, **kw)
if _is_deepseek_model(model):
@@ -1172,6 +1298,9 @@ class CloudEngine(InferenceEngine):
elif _is_openrouter_model(model):
async for token in self._stream_openrouter(messages, **kw):
yield token
+ elif _is_atlascloud_model(model):
+ async for token in self._stream_atlascloud(messages, **kw):
+ yield token
elif _is_minimax_model(model):
async for token in self._stream_minimax(messages, **kw):
yield token
@@ -1524,6 +1653,38 @@ class CloudEngine(InferenceEngine):
if delta and delta.content:
yield delta.content
+ async def _stream_atlascloud(
+ self,
+ messages: Sequence[Message],
+ *,
+ model: str,
+ temperature: float,
+ max_tokens: int,
+ **kwargs: Any,
+ ) -> AsyncIterator[str]:
+ if self._atlascloud_client is None:
+ raise EngineConnectionError("Atlas Cloud client not available")
+ actual_model = model.removeprefix("atlascloud/")
+ create_kwargs: Dict[str, Any] = {
+ "model": actual_model,
+ "messages": messages_to_dicts(messages),
+ "max_tokens": max_tokens,
+ "temperature": temperature,
+ "stream": True,
+ }
+ # Forward tools / tool_choice (Atlas Cloud is OpenAI-compatible).
+ tools = kwargs.pop("tools", None)
+ if tools:
+ create_kwargs["tools"] = tools
+ tool_choice = kwargs.pop("tool_choice", None)
+ if tool_choice is not None:
+ create_kwargs["tool_choice"] = tool_choice
+ resp = self._atlascloud_client.chat.completions.create(**create_kwargs)
+ for chunk in resp:
+ delta = chunk.choices[0].delta if chunk.choices else None
+ if delta and delta.content:
+ yield delta.content
+
async def _stream_minimax(
self,
messages: Sequence[Message],
@@ -1587,7 +1748,7 @@ class CloudEngine(InferenceEngine):
) -> AsyncIterator[StreamChunk]:
"""Yield StreamChunks from an OpenAI-compatible streaming response.
- Works for OpenAI, OpenRouter, MiniMax, and Codex.
+ Works for OpenAI, OpenRouter, Atlas Cloud, MiniMax, DeepSeek, and Codex.
"""
if _is_codex_model(model):
# Codex uses Responses API — fall back to base stream_full wrapper
@@ -1613,6 +1774,18 @@ class CloudEngine(InferenceEngine):
"stream": True,
**kwargs,
}
+ elif _is_atlascloud_model(model):
+ client = self._atlascloud_client
+ if client is None:
+ raise EngineConnectionError("Atlas Cloud client not available")
+ create_kwargs = {
+ "model": model.removeprefix("atlascloud/"),
+ "messages": messages_to_dicts(messages),
+ "max_tokens": max_tokens,
+ "temperature": temperature,
+ "stream": True,
+ **kwargs,
+ }
elif _is_minimax_model(model):
client = self._minimax_client
if client is None:
@@ -1803,6 +1976,8 @@ class CloudEngine(InferenceEngine):
models.extend(_GOOGLE_MODELS)
if self._openrouter_client is not None:
models.extend(_OPENROUTER_POPULAR)
+ if self._atlascloud_client is not None:
+ models.extend(_ATLASCLOUD_POPULAR)
if self._minimax_client is not None:
models.extend(_MINIMAX_MODELS)
if self._deepseek_client is not None:
@@ -1828,6 +2003,8 @@ class CloudEngine(InferenceEngine):
return self._codex_client
if _is_openrouter_model(model):
return self._openrouter_client
+ if _is_atlascloud_model(model):
+ return self._atlascloud_client
if _is_minimax_model(model):
return self._minimax_client
if _is_deepseek_model(model):
@@ -1859,6 +2036,7 @@ class CloudEngine(InferenceEngine):
or self._anthropic_client is not None
or self._google_client is not None
or self._openrouter_client is not None
+ or self._atlascloud_client is not None
or self._minimax_client is not None
or self._deepseek_client is not None
or self._codex_client is not None
@@ -1879,10 +2057,20 @@ class CloudEngine(InferenceEngine):
if hasattr(self._openrouter_client, "close"):
self._openrouter_client.close()
self._openrouter_client = None
+ if self._atlascloud_client is not None:
+ if hasattr(self._atlascloud_client, "close"):
+ self._atlascloud_client.close()
+ self._atlascloud_client = None
if self._minimax_client is not None:
if hasattr(self._minimax_client, "close"):
self._minimax_client.close()
self._minimax_client = None
+ # The DeepSeek client was never released here, so its httpx pool
+ # outlived close() (every other provider client is dropped).
+ if self._deepseek_client is not None:
+ if hasattr(self._deepseek_client, "close"):
+ self._deepseek_client.close()
+ self._deepseek_client = None
if self._codex_client is not None:
self._codex_client = None
diff --git a/src/openjarvis/intelligence/model_catalog.py b/src/openjarvis/intelligence/model_catalog.py
index 62507cc2..ae4e6f59 100644
--- a/src/openjarvis/intelligence/model_catalog.py
+++ b/src/openjarvis/intelligence/model_catalog.py
@@ -948,6 +948,134 @@ BUILTIN_MODELS: List[ModelSpec] = [
},
),
# -----------------------------------------------------------------------
+ # Cloud models — Atlas Cloud (OpenAI-compatible aggregator)
+ #
+ # IDs carry the "atlascloud/" routing prefix the cloud engine dispatches
+ # on. Context lengths and prices are the gateway's own, read from
+ # GET https://api.atlascloud.ai/v1/models (context_length, and
+ # pricing.prompt / pricing.completion in USD per token).
+ # -----------------------------------------------------------------------
+ ModelSpec(
+ model_id="atlascloud/openai/gpt-4.1-mini",
+ name="GPT-4.1 Mini (Atlas Cloud)",
+ parameter_count_b=0.0,
+ context_length=1_047_576,
+ supported_engines=("cloud",),
+ provider="atlascloud",
+ requires_api_key=True,
+ metadata={
+ "architecture": "proprietary",
+ "pricing_input": 0.4,
+ "pricing_output": 1.6,
+ "url": "https://www.atlascloud.ai/models",
+ },
+ ),
+ ModelSpec(
+ model_id="atlascloud/openai/gpt-5.4-mini",
+ name="GPT-5.4 Mini (Atlas Cloud)",
+ parameter_count_b=0.0,
+ context_length=400_000,
+ supported_engines=("cloud",),
+ provider="atlascloud",
+ requires_api_key=True,
+ metadata={
+ "architecture": "proprietary",
+ "pricing_input": 0.75,
+ "pricing_output": 4.5,
+ "url": "https://www.atlascloud.ai/models",
+ },
+ ),
+ ModelSpec(
+ model_id="atlascloud/deepseek-ai/deepseek-v3.2",
+ name="DeepSeek V3.2 (Atlas Cloud)",
+ parameter_count_b=0.0,
+ context_length=163_840,
+ supported_engines=("cloud",),
+ provider="atlascloud",
+ requires_api_key=True,
+ metadata={
+ "architecture": "moe",
+ "pricing_input": 0.26,
+ "pricing_output": 0.38,
+ "url": "https://www.atlascloud.ai/models",
+ },
+ ),
+ ModelSpec(
+ model_id="atlascloud/Qwen/Qwen3-235B-A22B-Instruct-2507",
+ name="Qwen3 235B A22B Instruct (Atlas Cloud)",
+ parameter_count_b=0.0,
+ context_length=131_072,
+ supported_engines=("cloud",),
+ provider="atlascloud",
+ requires_api_key=True,
+ metadata={
+ "architecture": "moe",
+ "pricing_input": 0.2,
+ "pricing_output": 0.88,
+ "url": "https://www.atlascloud.ai/models",
+ },
+ ),
+ ModelSpec(
+ model_id="atlascloud/qwen/qwen3.5-35b-a3b",
+ name="Qwen3.5 35B A3B (Atlas Cloud)",
+ parameter_count_b=0.0,
+ context_length=262_144,
+ supported_engines=("cloud",),
+ provider="atlascloud",
+ requires_api_key=True,
+ metadata={
+ "architecture": "moe",
+ "pricing_input": 0.225,
+ "pricing_output": 1.8,
+ "url": "https://www.atlascloud.ai/models",
+ },
+ ),
+ ModelSpec(
+ model_id="atlascloud/zai-org/GLM-4.6",
+ name="GLM-4.6 (Atlas Cloud)",
+ parameter_count_b=0.0,
+ context_length=202_752,
+ supported_engines=("cloud",),
+ provider="atlascloud",
+ requires_api_key=True,
+ metadata={
+ "architecture": "moe",
+ "pricing_input": 0.6,
+ "pricing_output": 2.2,
+ "url": "https://www.atlascloud.ai/models",
+ },
+ ),
+ ModelSpec(
+ model_id="atlascloud/moonshotai/kimi-k2.5",
+ name="Kimi K2.5 (Atlas Cloud)",
+ parameter_count_b=0.0,
+ context_length=262_144,
+ supported_engines=("cloud",),
+ provider="atlascloud",
+ requires_api_key=True,
+ metadata={
+ "architecture": "moe",
+ "pricing_input": 0.49,
+ "pricing_output": 2.5,
+ "url": "https://www.atlascloud.ai/models",
+ },
+ ),
+ ModelSpec(
+ model_id="atlascloud/minimaxai/minimax-m2.5",
+ name="MiniMax M2.5 (Atlas Cloud)",
+ parameter_count_b=0.0,
+ context_length=196_608,
+ supported_engines=("cloud",),
+ provider="atlascloud",
+ requires_api_key=True,
+ metadata={
+ "architecture": "moe",
+ "pricing_input": 0.295,
+ "pricing_output": 1.2,
+ "url": "https://www.atlascloud.ai/models",
+ },
+ ),
+ # -----------------------------------------------------------------------
# Cloud models — Google
# -----------------------------------------------------------------------
ModelSpec(
diff --git a/src/openjarvis/server/cloud_router.py b/src/openjarvis/server/cloud_router.py
index 85695265..53d4a9e7 100644
--- a/src/openjarvis/server/cloud_router.py
+++ b/src/openjarvis/server/cloud_router.py
@@ -27,6 +27,10 @@ _OPENAI_PREFIXES = ("gpt-", "o1-", "o3-", "o4-", "chatgpt-")
_ANTHROPIC_PREFIXES = ("claude-",)
_GOOGLE_PREFIXES = ("gemini-",)
_MINIMAX_PREFIXES = ("MiniMax-",)
+# Atlas Cloud IDs are already "vendor/model", so they must be recognised by
+# their routing prefix before the generic '"/" means OpenRouter' fallback
+# below — otherwise "atlascloud/openai/gpt-4.1-mini" is sent to OpenRouter.
+_ATLASCLOUD_PREFIX = "atlascloud/"
# HuggingFace orgs that host local-only quantised models — never route to cloud.
_LOCAL_HF_ORGS = (
@@ -55,6 +59,7 @@ def _load_keys() -> dict[str, str]:
"GOOGLE_API_KEY",
"OPENROUTER_API_KEY",
"MINIMAX_API_KEY",
+ "ATLASCLOUD_API_KEY",
):
val = os.environ.get(name)
if val:
@@ -72,6 +77,8 @@ def get_provider(model: str) -> str | None:
return "google"
if any(model.startswith(p) for p in _MINIMAX_PREFIXES):
return "minimax"
+ if model.startswith(_ATLASCLOUD_PREFIX):
+ return "atlascloud"
if any(model.startswith(org) for org in _LOCAL_HF_ORGS):
return None # local model, never route to cloud
if "/" in model: # openrouter format: "meta-llama/llama-3-8b"
@@ -391,6 +398,23 @@ async def stream_cloud(
):
yield token
+ elif provider == "atlascloud":
+ keys = _load_keys()
+ api_key = keys.get("ATLASCLOUD_API_KEY", "")
+ if not api_key:
+ raise ValueError(
+ "ATLASCLOUD_API_KEY not set — add it in the Cloud Models tab"
+ )
+ async for token in _stream_openai(
+ model.removeprefix(_ATLASCLOUD_PREFIX),
+ messages,
+ temperature,
+ max_tokens,
+ base_url="https://api.atlascloud.ai/v1",
+ api_key_name="ATLASCLOUD_API_KEY",
+ ):
+ yield token
+
elif provider == "minimax":
keys = _load_keys()
api_key = keys.get("MINIMAX_API_KEY", "")
diff --git a/tests/engine/test_cloud_atlascloud.py b/tests/engine/test_cloud_atlascloud.py
new file mode 100644
index 00000000..f3f6a25f
--- /dev/null
+++ b/tests/engine/test_cloud_atlascloud.py
@@ -0,0 +1,441 @@
+"""Tests for Atlas Cloud cloud-provider support.
+
+Atlas Cloud is an OpenAI-compatible aggregator, so the interesting surface is
+not the HTTP call (that is the shared OpenAI SDK) but the *routing*: its model
+IDs are already ``vendor/model``, which collides with three existing rules —
+the ``"claude" in model`` / ``"gemini" in model`` substring predicates and the
+``"/" in model means OpenRouter`` fallback in the server-side cloud router.
+These tests pin that an ``atlascloud/``-prefixed ID always reaches the Atlas
+client and never leaks into another provider's.
+"""
+
+from __future__ import annotations
+
+from types import SimpleNamespace
+from unittest import mock
+
+import pytest
+
+from openjarvis.core.registry import EngineRegistry
+from openjarvis.core.types import Message, Role
+from openjarvis.engine._base import EngineConnectionError
+from openjarvis.engine.cloud import (
+ _ATLASCLOUD_POPULAR,
+ PRICING,
+ CloudEngine,
+ _is_anthropic_model,
+ _is_atlascloud_model,
+ _is_google_model,
+ _is_minimax_model,
+ _is_openai_model,
+ estimate_cost,
+)
+from openjarvis.intelligence.model_catalog import BUILTIN_MODELS
+from openjarvis.server import cloud_router
+
+_ALL_CLOUD_KEYS = (
+ "OPENAI_API_KEY",
+ "ANTHROPIC_API_KEY",
+ "GEMINI_API_KEY",
+ "GOOGLE_API_KEY",
+ "OPENROUTER_API_KEY",
+ "MINIMAX_API_KEY",
+ "DEEPSEEK_API_KEY",
+ "ATLASCLOUD_API_KEY",
+)
+
+_DEFAULT_MODEL = "atlascloud/openai/gpt-4.1-mini"
+
+
+def _make_cloud_engine(monkeypatch: pytest.MonkeyPatch) -> CloudEngine:
+ """Create a CloudEngine with all API keys cleared."""
+ for name in _ALL_CLOUD_KEYS:
+ monkeypatch.delenv(name, raising=False)
+ if not EngineRegistry.contains("cloud"):
+ EngineRegistry.register_value("cloud", CloudEngine)
+ return CloudEngine()
+
+
+def _fake_response(
+ content: str = "Hello from Atlas Cloud!",
+ model: str = "openai/gpt-4.1-mini",
+ prompt_tokens: int = 10,
+ completion_tokens: int = 5,
+ tool_calls: list | None = None,
+) -> SimpleNamespace:
+ usage = SimpleNamespace(
+ prompt_tokens=prompt_tokens,
+ completion_tokens=completion_tokens,
+ total_tokens=prompt_tokens + completion_tokens,
+ )
+ message = SimpleNamespace(content=content, tool_calls=tool_calls)
+ choice = SimpleNamespace(message=message, finish_reason="stop")
+ return SimpleNamespace(choices=[choice], usage=usage, model=model)
+
+
+# ---------------------------------------------------------------------------
+# Routing
+# ---------------------------------------------------------------------------
+
+
+class TestAtlasCloudRouting:
+ def test_is_atlascloud_model(self) -> None:
+ assert _is_atlascloud_model(_DEFAULT_MODEL) is True
+ assert _is_atlascloud_model("atlascloud/zai-org/GLM-4.6") is True
+ assert _is_atlascloud_model("openai/gpt-4.1-mini") is False
+ assert _is_atlascloud_model("gpt-4o") is False
+ assert _is_atlascloud_model("openrouter/openai/gpt-4o") is False
+
+ def test_prefixed_claude_does_not_route_to_anthropic(self) -> None:
+ """``"claude" in model`` would otherwise swallow the aggregator ID."""
+ assert _is_anthropic_model("claude-sonnet-4-6") is True
+ assert _is_anthropic_model("atlascloud/anthropic/claude-sonnet-4-6") is False
+
+ def test_prefixed_gemini_does_not_route_to_google(self) -> None:
+ assert _is_google_model("gemini-3-pro") is True
+ assert _is_google_model("atlascloud/google/gemini-3-pro") is False
+
+ def test_prefixed_minimax_does_not_route_to_minimax_direct(self) -> None:
+ """Atlas serves a MiniMax model; direct-MiniMax must not claim it."""
+ assert _is_minimax_model("MiniMax-M2.5") is True
+ assert _is_minimax_model("atlascloud/minimaxai/minimax-m2.5") is False
+
+ def test_prefixed_gpt_does_not_route_to_openai_direct(self) -> None:
+ assert _is_openai_model("gpt-4o") is True
+ assert _is_openai_model(_DEFAULT_MODEL) is False
+
+ def test_popular_models_all_carry_the_prefix(self) -> None:
+ assert _ATLASCLOUD_POPULAR
+ for model in _ATLASCLOUD_POPULAR:
+ assert model.startswith("atlascloud/"), model
+
+ def test_default_model_is_first(self) -> None:
+ assert _ATLASCLOUD_POPULAR[0] == _DEFAULT_MODEL
+
+
+# ---------------------------------------------------------------------------
+# Client init / lifecycle
+# ---------------------------------------------------------------------------
+
+
+class TestAtlasCloudInit:
+ def test_init_with_api_key(self, monkeypatch: pytest.MonkeyPatch) -> None:
+ for name in _ALL_CLOUD_KEYS:
+ monkeypatch.delenv(name, raising=False)
+ monkeypatch.setenv("ATLASCLOUD_API_KEY", "apikey-test")
+ fake_openai = mock.MagicMock()
+ with mock.patch.dict("sys.modules", {"openai": fake_openai}):
+ if not EngineRegistry.contains("cloud"):
+ EngineRegistry.register_value("cloud", CloudEngine)
+ engine = CloudEngine()
+ assert engine._atlascloud_client is not None
+ fake_openai.OpenAI.assert_called_once_with(
+ base_url="https://api.atlascloud.ai/v1", api_key="apikey-test"
+ )
+
+ def test_health_with_atlascloud_key_only(
+ self, monkeypatch: pytest.MonkeyPatch
+ ) -> None:
+ for name in _ALL_CLOUD_KEYS:
+ monkeypatch.delenv(name, raising=False)
+ monkeypatch.setenv("ATLASCLOUD_API_KEY", "apikey-test")
+ with mock.patch.dict("sys.modules", {"openai": mock.MagicMock()}):
+ engine = CloudEngine()
+ assert engine.health() is True
+
+ def test_no_key_no_client(self, monkeypatch: pytest.MonkeyPatch) -> None:
+ engine = _make_cloud_engine(monkeypatch)
+ assert engine._atlascloud_client is None
+
+ def test_list_models_only_when_configured(
+ self, monkeypatch: pytest.MonkeyPatch
+ ) -> None:
+ engine = _make_cloud_engine(monkeypatch)
+ assert _DEFAULT_MODEL not in engine.list_models()
+ engine._atlascloud_client = mock.MagicMock()
+ assert set(_ATLASCLOUD_POPULAR).issubset(set(engine.list_models()))
+
+ def test_can_serve_requires_the_atlas_client(
+ self, monkeypatch: pytest.MonkeyPatch
+ ) -> None:
+ engine = _make_cloud_engine(monkeypatch)
+ assert engine.can_serve(_DEFAULT_MODEL) is False
+ engine._atlascloud_client = mock.MagicMock()
+ assert engine.can_serve(_DEFAULT_MODEL) is True
+
+ def test_close_releases_the_client(self, monkeypatch: pytest.MonkeyPatch) -> None:
+ engine = _make_cloud_engine(monkeypatch)
+ client = mock.MagicMock()
+ engine._atlascloud_client = client
+ engine.close()
+ client.close.assert_called_once()
+ assert engine._atlascloud_client is None
+
+ def test_close_also_releases_the_deepseek_client(
+ self, monkeypatch: pytest.MonkeyPatch
+ ) -> None:
+ """Regression: close() used to leave _deepseek_client (and its httpx
+ connection pool) alive while dropping every other provider client."""
+ engine = _make_cloud_engine(monkeypatch)
+ client = mock.MagicMock()
+ engine._deepseek_client = client
+ engine.close()
+ client.close.assert_called_once()
+ assert engine._deepseek_client is None
+
+
+# ---------------------------------------------------------------------------
+# generate()
+# ---------------------------------------------------------------------------
+
+
+class TestAtlasCloudGenerate:
+ def test_generate_strips_the_prefix_before_calling_the_gateway(
+ self, monkeypatch: pytest.MonkeyPatch
+ ) -> None:
+ engine = _make_cloud_engine(monkeypatch)
+ client = mock.MagicMock()
+ client.chat.completions.create.return_value = _fake_response()
+ engine._atlascloud_client = client
+
+ result = engine.generate(
+ [Message(role=Role.USER, content="Hi")], model=_DEFAULT_MODEL
+ )
+
+ sent = client.chat.completions.create.call_args.kwargs
+ assert sent["model"] == "openai/gpt-4.1-mini"
+ assert result["content"] == "Hello from Atlas Cloud!"
+ assert result["usage"]["prompt_tokens"] == 10
+ assert result["usage"]["completion_tokens"] == 5
+ assert result["finish_reason"] == "stop"
+
+ @pytest.mark.parametrize("model", _ATLASCLOUD_POPULAR)
+ def test_every_listed_model_routes_to_the_atlas_client(
+ self, monkeypatch: pytest.MonkeyPatch, model: str
+ ) -> None:
+ engine = _make_cloud_engine(monkeypatch)
+ client = mock.MagicMock()
+ client.chat.completions.create.return_value = _fake_response(model=model)
+ engine._atlascloud_client = client
+ # Every other provider client stays None: reaching one would raise.
+ engine.generate([Message(role=Role.USER, content="Hi")], model=model)
+ assert client.chat.completions.create.call_count == 1
+
+ def test_generate_without_a_client_names_the_env_var(
+ self, monkeypatch: pytest.MonkeyPatch
+ ) -> None:
+ engine = _make_cloud_engine(monkeypatch)
+ with pytest.raises(EngineConnectionError, match="ATLASCLOUD_API_KEY"):
+ engine.generate(
+ [Message(role=Role.USER, content="Hi")], model=_DEFAULT_MODEL
+ )
+
+ def test_tools_and_tool_choice_are_forwarded(
+ self, monkeypatch: pytest.MonkeyPatch
+ ) -> None:
+ engine = _make_cloud_engine(monkeypatch)
+ client = mock.MagicMock()
+ client.chat.completions.create.return_value = _fake_response()
+ engine._atlascloud_client = client
+ tools = [{"type": "function", "function": {"name": "search"}}]
+
+ engine.generate(
+ [Message(role=Role.USER, content="Hi")],
+ model=_DEFAULT_MODEL,
+ tools=tools,
+ tool_choice="auto",
+ )
+
+ sent = client.chat.completions.create.call_args.kwargs
+ assert sent["tools"] == tools
+ assert sent["tool_choice"] == "auto"
+
+ def test_response_format_is_forwarded(
+ self, monkeypatch: pytest.MonkeyPatch
+ ) -> None:
+ """Unlike OpenRouter, the gateway honours OpenAI JSON mode."""
+ engine = _make_cloud_engine(monkeypatch)
+ client = mock.MagicMock()
+ client.chat.completions.create.return_value = _fake_response()
+ engine._atlascloud_client = client
+
+ engine.generate(
+ [Message(role=Role.USER, content="Hi")],
+ model=_DEFAULT_MODEL,
+ response_format={"type": "json_object"},
+ )
+
+ sent = client.chat.completions.create.call_args.kwargs
+ assert sent["response_format"] == {"type": "json_object"}
+
+ def test_tool_calls_are_normalised(self, monkeypatch: pytest.MonkeyPatch) -> None:
+ engine = _make_cloud_engine(monkeypatch)
+ client = mock.MagicMock()
+ client.chat.completions.create.return_value = _fake_response(
+ content="",
+ tool_calls=[
+ SimpleNamespace(
+ id="call_1",
+ type="function",
+ function=SimpleNamespace(name="search", arguments='{"q":"x"}'),
+ )
+ ],
+ )
+ engine._atlascloud_client = client
+
+ result = engine.generate(
+ [Message(role=Role.USER, content="Hi")], model=_DEFAULT_MODEL
+ )
+
+ assert result["tool_calls"] == [
+ {
+ "id": "call_1",
+ "type": "function",
+ "function": {"name": "search", "arguments": '{"q":"x"}'},
+ }
+ ]
+
+
+# ---------------------------------------------------------------------------
+# stream()
+# ---------------------------------------------------------------------------
+
+
+class TestAtlasCloudStream:
+ @pytest.mark.asyncio
+ async def test_stream_yields_content_deltas(
+ self, monkeypatch: pytest.MonkeyPatch
+ ) -> None:
+ engine = _make_cloud_engine(monkeypatch)
+ client = mock.MagicMock()
+ client.chat.completions.create.return_value = [
+ SimpleNamespace(choices=[SimpleNamespace(delta=SimpleNamespace(content=c))])
+ for c in ("Hel", "lo")
+ ] + [SimpleNamespace(choices=[])]
+ engine._atlascloud_client = client
+
+ tokens = [
+ t
+ async for t in engine.stream(
+ [Message(role=Role.USER, content="Hi")], model=_DEFAULT_MODEL
+ )
+ ]
+
+ assert tokens == ["Hel", "lo"]
+ sent = client.chat.completions.create.call_args.kwargs
+ assert sent["model"] == "openai/gpt-4.1-mini"
+ assert sent["stream"] is True
+
+ @pytest.mark.asyncio
+ async def test_stream_without_a_client_raises(
+ self, monkeypatch: pytest.MonkeyPatch
+ ) -> None:
+ engine = _make_cloud_engine(monkeypatch)
+ with pytest.raises(EngineConnectionError, match="Atlas Cloud"):
+ async for _ in engine.stream(
+ [Message(role=Role.USER, content="Hi")], model=_DEFAULT_MODEL
+ ):
+ pass
+
+ @pytest.mark.asyncio
+ async def test_stream_full_strips_the_prefix(
+ self, monkeypatch: pytest.MonkeyPatch
+ ) -> None:
+ engine = _make_cloud_engine(monkeypatch)
+ client = mock.MagicMock()
+ client.chat.completions.create.return_value = [
+ SimpleNamespace(
+ choices=[
+ SimpleNamespace(
+ delta=SimpleNamespace(content="hi", tool_calls=None),
+ finish_reason=None,
+ )
+ ]
+ )
+ ]
+ engine._atlascloud_client = client
+
+ chunks = [
+ c
+ async for c in engine._stream_full_openai(
+ [Message(role=Role.USER, content="Hi")],
+ model="atlascloud/zai-org/GLM-4.6",
+ temperature=0.7,
+ max_tokens=32,
+ )
+ ]
+
+ assert client.chat.completions.create.call_args.kwargs["model"] == (
+ "zai-org/GLM-4.6"
+ )
+ assert [c.content for c in chunks] == ["hi"]
+
+
+# ---------------------------------------------------------------------------
+# Pricing / catalog
+# ---------------------------------------------------------------------------
+
+
+class TestAtlasCloudPricing:
+ @pytest.mark.parametrize("model", _ATLASCLOUD_POPULAR)
+ def test_every_listed_model_has_a_rate(self, model: str) -> None:
+ assert model in PRICING, f"{model} would silently cost $0"
+ assert estimate_cost(model, 1_000_000, 1_000_000) > 0.0
+
+ def test_cost_uses_the_atlas_rate_not_the_direct_vendor_rate(self) -> None:
+ """``atlascloud/minimaxai/minimax-m2.5`` and ``MiniMax-M2.5`` are
+ different line items — a prefix collision here would misprice."""
+ atlas = estimate_cost("atlascloud/minimaxai/minimax-m2.5", 1_000_000, 0)
+ direct = estimate_cost("MiniMax-M2.5", 1_000_000, 0)
+ assert atlas == pytest.approx(0.295)
+ assert direct == pytest.approx(0.30)
+
+ def test_generate_reports_cost(self, monkeypatch: pytest.MonkeyPatch) -> None:
+ engine = _make_cloud_engine(monkeypatch)
+ client = mock.MagicMock()
+ client.chat.completions.create.return_value = _fake_response(
+ prompt_tokens=1_000_000, completion_tokens=1_000_000
+ )
+ engine._atlascloud_client = client
+
+ result = engine.generate(
+ [Message(role=Role.USER, content="Hi")], model=_DEFAULT_MODEL
+ )
+
+ assert result["cost_usd"] == pytest.approx(0.40 + 1.60)
+
+ def test_catalog_entries_match_the_pricing_table(self) -> None:
+ specs = {s.model_id: s for s in BUILTIN_MODELS if s.provider == "atlascloud"}
+ assert set(specs) == set(_ATLASCLOUD_POPULAR)
+ for model_id, spec in specs.items():
+ assert spec.requires_api_key is True
+ assert spec.supported_engines == ("cloud",)
+ rate_in, rate_out = PRICING[model_id]
+ assert spec.metadata["pricing_input"] == pytest.approx(rate_in)
+ assert spec.metadata["pricing_output"] == pytest.approx(rate_out)
+
+
+# ---------------------------------------------------------------------------
+# Server-side cloud router
+# ---------------------------------------------------------------------------
+
+
+class TestAtlasCloudServerRouting:
+ def test_provider_is_atlascloud_not_openrouter(self) -> None:
+ """The router's ``"/" in model`` fallback means OpenRouter; the
+ atlascloud prefix has to win before it."""
+ assert cloud_router.get_provider(_DEFAULT_MODEL) == "atlascloud"
+ assert cloud_router.get_provider("meta-llama/llama-3-8b") == "openrouter"
+
+ def test_prefixed_claude_is_not_classified_as_anthropic(self) -> None:
+ assert cloud_router.get_provider("claude-sonnet-4-6") == "anthropic"
+ assert (
+ cloud_router.get_provider("atlascloud/anthropic/claude-sonnet-4-6")
+ == "atlascloud"
+ )
+
+ def test_is_cloud_model(self) -> None:
+ assert cloud_router.is_cloud_model(_DEFAULT_MODEL) is True
+
+ def test_local_hf_orgs_still_win(self) -> None:
+ assert cloud_router.get_provider("unsloth/MiniMax-M2.5-GGUF") is None
diff --git a/tests/integration/test_atlascloud_cloud.py b/tests/integration/test_atlascloud_cloud.py
new file mode 100644
index 00000000..76bb3731
--- /dev/null
+++ b/tests/integration/test_atlascloud_cloud.py
@@ -0,0 +1,103 @@
+"""Integration test for the Atlas Cloud cloud provider.
+
+Requires the ATLASCLOUD_API_KEY environment variable to be set.
+Run with: pytest tests/integration/test_atlascloud_cloud.py -v
+"""
+
+from __future__ import annotations
+
+import os
+
+import pytest
+
+from openjarvis.core.registry import EngineRegistry
+from openjarvis.core.types import Message, Role
+from openjarvis.engine.cloud import _ATLASCLOUD_POPULAR, CloudEngine
+
+_ATLASCLOUD_KEY = os.environ.get("ATLASCLOUD_API_KEY", "")
+_skip_no_key = pytest.mark.skipif(
+ not _ATLASCLOUD_KEY,
+ reason="ATLASCLOUD_API_KEY not set",
+)
+
+_DEFAULT_MODEL = "atlascloud/openai/gpt-4.1-mini"
+
+
+@_skip_no_key
+class TestAtlasCloudIntegration:
+ """Live integration tests against the Atlas Cloud gateway."""
+
+ @pytest.fixture()
+ def engine(self, monkeypatch: pytest.MonkeyPatch) -> CloudEngine:
+ monkeypatch.setenv("ATLASCLOUD_API_KEY", _ATLASCLOUD_KEY)
+ for name in (
+ "OPENAI_API_KEY",
+ "ANTHROPIC_API_KEY",
+ "GEMINI_API_KEY",
+ "GOOGLE_API_KEY",
+ "OPENROUTER_API_KEY",
+ "MINIMAX_API_KEY",
+ "DEEPSEEK_API_KEY",
+ ):
+ monkeypatch.delenv(name, raising=False)
+ if not EngineRegistry.contains("cloud"):
+ EngineRegistry.register_value("cloud", CloudEngine)
+ return CloudEngine()
+
+ def test_basic_chat(self, engine: CloudEngine) -> None:
+ """Send a simple message and verify a non-empty, costed response."""
+ result = engine.generate(
+ [Message(role=Role.USER, content="Reply with exactly: hello world")],
+ model=_DEFAULT_MODEL,
+ temperature=0.01,
+ max_tokens=32,
+ )
+ assert result["content"], "Expected non-empty content"
+ assert result["usage"]["prompt_tokens"] > 0
+ assert result["usage"]["completion_tokens"] > 0
+ assert result["finish_reason"] in ("stop", "length")
+ assert result["cost_usd"] > 0.0
+
+ @pytest.mark.asyncio
+ async def test_streaming(self, engine: CloudEngine) -> None:
+ tokens = [
+ t
+ async for t in engine.stream(
+ [Message(role=Role.USER, content="Count: 1 2 3")],
+ model=_DEFAULT_MODEL,
+ temperature=0.01,
+ max_tokens=32,
+ )
+ ]
+ assert "".join(tokens).strip()
+
+ def test_tool_calling(self, engine: CloudEngine) -> None:
+ """The gateway forwards OpenAI tool calls unchanged."""
+ result = engine.generate(
+ [Message(role=Role.USER, content="What is the weather in Paris?")],
+ model=_DEFAULT_MODEL,
+ temperature=0.01,
+ max_tokens=128,
+ tools=[
+ {
+ "type": "function",
+ "function": {
+ "name": "get_weather",
+ "description": "Look up the current weather for a city.",
+ "parameters": {
+ "type": "object",
+ "properties": {"city": {"type": "string"}},
+ "required": ["city"],
+ },
+ },
+ }
+ ],
+ )
+ assert result["tool_calls"], "Expected the model to call get_weather"
+ assert result["tool_calls"][0]["function"]["name"] == "get_weather"
+
+ def test_health_and_list_models(self, engine: CloudEngine) -> None:
+ assert engine.health() is True
+ models = engine.list_models()
+ for model in _ATLASCLOUD_POPULAR:
+ assert model in models