Skip to content
HaneDOCS日本語

Hane Platform

Model Gateway

What the Model Gateway does when agents and Hane Cowork use models, per-organization settings, limits, and call records.

This page explains the Model Gateway, the single way models are called from within Hane. It shows how your organization decides and enforces who can use which models, and how much.

The Model Gateway is a checkpoint that keeps agents in sandboxes, and Hane Cowork on employees’ PCs, from calling model providers directly.

  • Real keys never leave Hane. Provider API keys stay inside Hane and are never given to sandboxes or PCs. Callers only hold short-lived credentials tied to a run or a conversation.
  • Every call is checked. Credentials, allowed models, budget, and run state are checked on each call.
  • Every call is recorded. No model call stays invisible to your organization.
opencode in a sandbox ──┐
├─(short-lived credential)─> Model Gateway ─(real key)─> upstream model
Hane Cowork on a PC ────┘ │
└─> call records and budgets
Caller Entry point Credential
Agents with driver: opencode OpenAI-compatible chat completions A model RunToken tied to the AgentRun. It is separate from the Tool Gateway token; mixing them up is rejected
Local conversations in Hane Cowork A Cowork-only OpenAI-compatible chat completions endpoint A 5-minute credential tied to the user, organization, project, and environment, refreshed before it expires
  1. Requests from browsers (with an Origin header) are refused.
  2. The credential’s signature, expiry, and audience are verified. Using an agent model token at the Cowork endpoint, or the reverse, is rejected.
  3. The model must be on the environment’s list of allowed models. Other models are rejected; Hane never falls back to a different model.
  4. Limits apply to output tokens and request size.
  5. The run or conversation must still be active and the budget must have room. Calls for finished or cancelled runs, or with an exhausted budget, are rejected.
  6. The request goes upstream, and the response streams straight back while Hane reads the usage. During streaming, Hane rechecks the state every few seconds and cuts the call if it has been stopped.

Model use by agents is limited by modelTokensPerDay in the project and environment’s Budget, and by limits.maxModelTokens in the agent definition. Hane reserves maxModelTokens from the daily budget when a run starts, so runs started in parallel cannot exceed the limit together. See Agents and AgentRuns for an example.

Whether Hane Cowork can use models is set per project and environment. Changing the setting requires cowork:manage. Without a setting, Cowork cannot use models.

PUT /v1/cowork/policy
If-Match: "3"
Content-Type: application/json
{
"enabled": true,
"models": ["@cf/zai-org/glm-4.7-flash"],
"daily_token_limit": 2000000,
"session_token_limit": 200000,
"max_output_tokens": 4096
}
Field Meaning
enabled Whether Cowork may use models in this project and environment
models Allowed models. Only those the environment’s upstream also offers become usable (available_models)
daily_token_limit Tokens that can be used per day
session_token_limit Tokens that can be used in one conversation
max_output_tokens Maximum output tokens per call
local_tools Allow, confirm, or deny for each local capability (files, commands, browser, computer use, external transfer)

With cowork:run, users start, refresh, and revoke model access for their own conversations (/v1/cowork/model-sessions). Revoking rejects new calls immediately and cuts calls in progress. Local capability rules are covered in Administering Hane Cowork.

The Model Gateway creates a record before sending a call upstream and finalizes it with the actual usage when the call ends. If a call never finishes recording, it is counted conservatively as unknown, using the reserved amount.

Recorded Not recorded
Organization, project, environment, agent and run (conversation for Cowork) Prompt text
Model, input and output tokens, whether usage was estimated Response text
Latency and outcome (ok, error, cancelled, stopped, unknown) Credentials
Cost units returned by the upstream (only for providers that return them)

For agents, GET /v1/agents/model-usage returns totals per day, agent, and model. The console’s “Usage and budgets” page shows them too. For Cowork, users read their own records with GET /v1/cowork/model-sessions/{session_id}/invocations.