Skip to content

Commit 5bf9170

Browse files
cdoernclaude
andauthored
feat(ogx-api): introduce ogx_api.provider and ogx_api.types namespaces (#5740)
## Summary Splits the public surface of the `ogx-api` Python package into two import namespaces, as called out in the API Stability policy work in #5719. No file moves, no behavioral changes — just aggregate `__init__.py` modules that re-export from existing per-API submodules. - **`ogx_api.provider`** (59 symbols) — Provider SDK surface for out-of-tree providers: `Api`, `ProviderSpec`/`InlineProviderSpec`/`RemoteProviderSpec`, protocol classes (`Inference`, `Responses`, `VectorIO`, `Safety`, `Files`, …), schema utilities (`webmethod`, `json_schema_type`, `register_schema`), `Resource`/`ResourceType`, version constants, validators. Levelled as a single `v1`-stable contract per the policy. - **`ogx_api.types`** (413 symbols) — API datatype surface: request/response Pydantic models, content blocks, errors, value types. Each datatype's stability is inherited from the highest-stability route that references it. Shared resource/value types (`Model`, `Shield`, `ToolGroup`, `VectorStore`) are canonically in `ogx_api.types` and re-exported from `ogx_api.provider` for provider-side ergonomics — these are the only allowed overlap. ### Backwards compatibility Top-level imports (`from ogx_api import X`) continue to work unchanged for every symbol. New code should prefer the explicit namespace path: ```python from ogx_api.provider import Api, Inference, ProviderSpec from ogx_api.types import OpenAIResponseObject, ChatCompletionMessage ``` ### Out of scope - Physically moving files into the new directories. - Deprecating or warning on top-level imports. - Touching internal `ogx` server imports. ## Test plan - [x] New contract test `tests/unit/test_ogx_api_namespaces.py` (5 cases): asserts disjoint namespaces, top-level back-compat (every namespaced symbol resolves to the same object via `ogx_api`), and presence of core symbols. **All pass.** - [x] Broader unit-test sweep: `uv run pytest tests/unit/ --ignore=tests/unit/providers` → **973 passed**. Provider-test failures in this env are pre-existing missing optional deps (`moto`, `databricks`), not introduced here. - [x] `pre-commit run` clean on touched files (ruff, ruff-format, mypy, license-headers, API spec codegen all pass; the `check-init-py` hook fails on macOS bash 3.2 — pre-existing, unrelated). - [ ] CI to run `test-external.yml` and `test-external-provider-module.yml` against this branch to confirm out-of-tree provider builds still work via top-level imports. ## Related - Policy doc PR: #5719 (defines the two-surface model conceptually). This PR is the implementation. Trivial doc conflict expected on whichever merges second; either is straightforward to resolve. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: Charlie Doern <cdoern@redhat.com> Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
1 parent c95adb1 commit 5bf9170

5 files changed

Lines changed: 1209 additions & 0 deletions

File tree

docs/docs/concepts/apis/api_leveling.mdx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,15 @@ The leveling introduced in this document relates to the stability of the API and
7272

7373
Providers can iterate as much as they want on functionality as long as they work within the bounds of an API. If they need to change the API, then the API should not be `/v1`, or those breaking changes can only happen on a y-stream release basis.
7474

75+
### Public surfaces of the `ogx-api` package
76+
77+
The [`ogx-api`](https://pypi.org/project/ogx-api/) Python package — consumed by external/out-of-tree providers and SDK code generation — exposes two distinct public surfaces, each with its own stability rules:
78+
79+
- **`ogx_api.provider`** — the Provider SDK: `Api` enum, `ProviderSpec` family, protocol classes (`Inference`, `Responses`, `VectorIO`, …), schema utilities, `Resource` base classes, version constants, validators. Levelled as a single cohesive contract; currently `v1`-stable. Removals or signature changes require a major version bump of `ogx-api`.
80+
- **`ogx_api.types`** — API datatypes: request/response Pydantic models, content blocks, errors, value types. Each datatype's level is inherited from the highest-stability route that references it (a type used by any `/v1` route is `v1`-stable).
81+
82+
Top-level imports (`from ogx_api import X`) remain supported for backwards compatibility and resolve to the same objects as the namespaced imports. New code should prefer the explicit namespace path to make the contract boundary obvious. Sub-module imports (`from ogx_api.responses import ...`) remain unsupported and are not covered by this policy.
83+
7584
### Approval and Announcement Process for Breaking Changes
7685

7786
- **PR Labeling**: Any pull request that introduces a breaking API change must be clearly labeled with `breaking-change`.

src/ogx_api/provider/__init__.py

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
# Copyright (c) The OGX Contributors.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the terms described in the LICENSE file in
5+
# the root directory of this source tree.
6+
7+
"""
8+
Provider SDK surface for OGX.
9+
10+
This namespace contains the symbols an out-of-tree provider needs to register
11+
itself with the OGX server: protocol classes, provider specs, the `Api` enum,
12+
the `webmethod` decorator, schema utilities, and shared resource/value types.
13+
14+
The Provider SDK surface is levelled as a single cohesive contract — see
15+
`docs/docs/concepts/apis/api_leveling.mdx` for the stability rules. The whole
16+
surface is `v1`-stable; removals or renames require a major version bump of
17+
the `ogx-api` package.
18+
19+
Symbols re-exported here also remain importable from the top level (`from
20+
ogx_api import X`) for backwards compatibility. New code should prefer
21+
`from ogx_api.provider import X` to make the contract explicit.
22+
"""
23+
24+
# Protocol classes — the abstract interfaces a provider implements.
25+
from ogx_api.admin import Admin
26+
from ogx_api.batches import Batches
27+
from ogx_api.connectors import Connectors
28+
from ogx_api.conversations import Conversations
29+
from ogx_api.datatypes import (
30+
Api,
31+
DynamicApiMeta,
32+
Error,
33+
ExternalApiSpec,
34+
HealthResponse,
35+
HealthStatus,
36+
InlineProviderSpec,
37+
ModelsProtocolPrivate,
38+
ProviderSpec,
39+
RemoteProviderConfig,
40+
RemoteProviderSpec,
41+
RoutingTable,
42+
ShieldsProtocolPrivate,
43+
ToolGroupsProtocolPrivate,
44+
VectorStoresProtocolPrivate,
45+
)
46+
from ogx_api.file_processors import FileProcessors
47+
from ogx_api.files import Files
48+
from ogx_api.inference import Inference, InferenceProvider, ModelStore
49+
from ogx_api.inspect_api import Inspect
50+
from ogx_api.interactions import Interactions
51+
from ogx_api.messages import Messages
52+
53+
# Shared resource/value types. Canonical home is `ogx_api.types`; re-exported
54+
# here because providers import them as part of registration / protocol
55+
# implementations.
56+
from ogx_api.models import Model, Models
57+
from ogx_api.prompts import Prompts
58+
from ogx_api.providers import Providers
59+
from ogx_api.resource import Resource, ResourceType
60+
from ogx_api.responses import Responses
61+
from ogx_api.safety import Safety, ShieldStore
62+
from ogx_api.schema_utils import (
63+
CallableT,
64+
ExtraBodyField,
65+
SchemaInfo,
66+
clear_dynamic_schema_types,
67+
get_registered_schema_info,
68+
iter_dynamic_schema_types,
69+
iter_json_schema_types,
70+
iter_registered_schema_types,
71+
json_schema_type,
72+
register_dynamic_schema_type,
73+
register_schema,
74+
)
75+
from ogx_api.shields import Shield, Shields
76+
from ogx_api.tools import ToolGroup, ToolGroups, ToolRuntime, ToolStore
77+
from ogx_api.validators import validate_embeddings_input_is_text
78+
from ogx_api.vector_io import VectorIO
79+
from ogx_api.vector_stores import VectorStore
80+
from ogx_api.version import OGX_API_V1, OGX_API_V1ALPHA, OGX_API_V1BETA
81+
82+
__all__ = [
83+
# Core provider machinery
84+
"Api",
85+
"DynamicApiMeta",
86+
"Error",
87+
"ExternalApiSpec",
88+
"HealthResponse",
89+
"HealthStatus",
90+
"InlineProviderSpec",
91+
"ProviderSpec",
92+
"RemoteProviderConfig",
93+
"RemoteProviderSpec",
94+
"RoutingTable",
95+
# Protocol-private mixins
96+
"ModelsProtocolPrivate",
97+
"ShieldsProtocolPrivate",
98+
"ToolGroupsProtocolPrivate",
99+
"VectorStoresProtocolPrivate",
100+
# Resource base classes
101+
"Resource",
102+
"ResourceType",
103+
# Schema utilities
104+
"CallableT",
105+
"ExtraBodyField",
106+
"SchemaInfo",
107+
"clear_dynamic_schema_types",
108+
"get_registered_schema_info",
109+
"iter_dynamic_schema_types",
110+
"iter_json_schema_types",
111+
"iter_registered_schema_types",
112+
"json_schema_type",
113+
"register_dynamic_schema_type",
114+
"register_schema",
115+
# Version constants
116+
"OGX_API_V1",
117+
"OGX_API_V1ALPHA",
118+
"OGX_API_V1BETA",
119+
# Validators
120+
"validate_embeddings_input_is_text",
121+
# API protocol classes
122+
"Admin",
123+
"Batches",
124+
"Connectors",
125+
"Conversations",
126+
"FileProcessors",
127+
"Files",
128+
"Inference",
129+
"InferenceProvider",
130+
"ModelStore",
131+
"Inspect",
132+
"Interactions",
133+
"Messages",
134+
"Models",
135+
"Prompts",
136+
"Providers",
137+
"Responses",
138+
"Safety",
139+
"ShieldStore",
140+
"Shields",
141+
"ToolGroups",
142+
"ToolRuntime",
143+
"ToolStore",
144+
"VectorIO",
145+
# Shared resource/value types (canonical home in ogx_api.types)
146+
"Model",
147+
"Shield",
148+
"ToolGroup",
149+
"VectorStore",
150+
]

src/ogx_api/pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ packages = [
6464
"ogx_api.tools",
6565
"ogx_api.vector_io",
6666
"ogx_api.connectors",
67+
"ogx_api.provider",
68+
"ogx_api.types",
6769
]
6870

6971
# 3. List every root-level .py file as a module.

0 commit comments

Comments
 (0)