Implementation:OpenHands OpenHands OrgService Create Org Entity
| Knowledge Sources | |
|---|---|
| Domains | Organization_Management, Multi_Tenancy |
| Last Updated | 2026-02-11 21:00 GMT |
Overview
Concrete tool for constructing an organization domain entity with default configuration and LiteLLM settings provided by the OpenHands enterprise storage layer.
Description
OrgService.create_org_entity constructs an Org model instance by combining user-supplied identity fields (name, contact name, contact email) with a system-generated UUID and default configuration values. After the base entity is constructed, apply_litellm_settings_to_org (at L118-129) merges the previously provisioned LiteLLM settings (team ID, API key hash, budget) into the organization object.
This method does not persist the entity to the database; it only builds the in-memory object. Persistence is handled by a subsequent step in the onboarding pipeline, allowing the workflow to compose the entity and its associated member record before committing them together in a single transaction.
Usage
Call this method after LiteLLM provisioning completes successfully. Pass the provisioned settings dictionary to populate the organization's LLM proxy configuration. The returned Org object is then passed to the persistence step along with the OrgMember entity.
Code Reference
Source Location
- Repository: OpenHands
- File:
enterprise/storage/org_service.py - Lines: L90-115 (create_org_entity), L118-129 (apply_litellm_settings_to_org)
Signature
def create_org_entity(
self,
org_id: UUID,
name: str,
contact_name: str,
contact_email: str,
) -> Org:
"""Construct an Org domain entity with defaults and identity fields.
Args:
org_id: The UUID for the new organization.
name: The organization name (already validated for uniqueness).
contact_name: The name of the primary contact.
contact_email: The email of the primary contact.
Returns:
A fully initialized Org instance (not yet persisted).
"""
def apply_litellm_settings_to_org(
org: Org,
settings: dict,
) -> None:
"""Apply provisioned LiteLLM settings to an Org entity in place.
Args:
org: The organization entity to update.
settings: The dictionary of LiteLLM settings from create_litellm_integration.
"""
Import
from enterprise.storage.org_service import OrgService
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| org_id | UUID | Yes | The UUID assigned to the new organization |
| name | str | Yes | The validated organization name |
| contact_name | str | Yes | The primary contact's full name |
| contact_email | str | Yes | The primary contact's email address |
Outputs
| Name | Type | Description |
|---|---|---|
| org | Org | A fully constructed Org model instance with defaults applied, ready for LiteLLM settings and persistence |
Usage Examples
Basic Usage
from uuid import uuid4
from enterprise.storage.org_service import OrgService
org_service = OrgService(session=db_session)
org_id = uuid4()
# Step 1: Construct the entity
org = org_service.create_org_entity(
org_id=org_id,
name="acme-corp",
contact_name="Jane Doe",
contact_email="jane@acme.com",
)
# Step 2: Apply LiteLLM settings obtained from create_litellm_integration
apply_litellm_settings_to_org(org, litellm_settings)
# org is now fully initialized and ready for persistence