Commit 197d9b3
Option C: rebuild SDK as a thin shell over the generated typed core
Replace the OpenAI-SDK delegation with a hand-written shell over the
OpenAPI-generated core (otari._client), generated from the otari spec.
The gateway is only OpenAI-compatible and has endpoints (notably the
Anthropic-shaped /messages) the OpenAI SDK cannot represent; generating
from the otari spec models the real contract.
Core (unmodified generator output) replaces the old _control_plane
subpackage and covers every endpoint with typed request/response models.
Shell (the real work):
- Auth modes preserved: platform -> Authorization: Bearer <token>;
non-platform -> Otari-Key: Bearer <key>; control-plane -> Authorization:
Bearer <admin/master key>. Fed into the generated ApiClient default
headers and the streaming shim's httpx requests.
- Ergonomic methods keep the existing public names/signatures
(completion/response/embedding/moderation/rerank/list_models/batches)
and add message(...) for the previously-missing /messages endpoint.
control_plane accessor now backed by _client.
- SSE streaming shim (_streaming.py): the generated core buffers and
cannot stream, so stream=True does a raw httpx streaming POST, parses
text/event-stream framing, terminates on [DONE], and yields typed
ChatCompletionChunk (chat) / parsed JSON (responses, messages).
- Typed error mapping: generated ApiException (.status/.body) -> the
errors.py hierarchy (Authentication 401/403, InsufficientFunds 402,
ModelNotFound 404, BatchNotComplete 409, RateLimit 429, GatewayTimeout
504, UpstreamProvider 502/5xx, UnsupportedCapability cross-mode, generic
OtariError). The streaming path adapts failed responses through the same
mapper.
- Async client wraps the sync generated core via asyncio.to_thread and
streams natively over httpx.AsyncClient.
Drop the openai dependency from inference. Update ruff/mypy excludes to
src/otari/_client. Rewrite unit tests to mock the generated transport
(RESTClientObject.request) and respx for SSE; control-plane integration
tests updated to import from _client and verified green against a live
gateway.
Note: chat streaming cannot be live-verified in this sandbox (no provider
key on the gateway); the SSE shim is unit-tested over mocked chunk bytes.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent 5a13bac commit 197d9b3
202 files changed
Lines changed: 25369 additions & 2183 deletions
File tree
- src/otari
- _client
- api
- models
- _control_plane
- api
- models
- tests
- integration
- unit
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
195 | 195 | | |
196 | 196 | | |
197 | 197 | | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
198 | 213 | | |
199 | 214 | | |
200 | 215 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
| 25 | + | |
26 | 26 | | |
27 | | - | |
| 27 | + | |
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| 43 | + | |
43 | 44 | | |
44 | 45 | | |
45 | 46 | | |
| |||
57 | 58 | | |
58 | 59 | | |
59 | 60 | | |
60 | | - | |
61 | | - | |
| 61 | + | |
| 62 | + | |
62 | 63 | | |
63 | 64 | | |
64 | 65 | | |
| |||
77 | 78 | | |
78 | 79 | | |
79 | 80 | | |
80 | | - | |
81 | | - | |
| 81 | + | |
| 82 | + | |
82 | 83 | | |
83 | 84 | | |
84 | | - | |
| 85 | + | |
85 | 86 | | |
86 | 87 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
37 | 36 | | |
38 | 37 | | |
39 | 38 | | |
40 | 39 | | |
41 | 40 | | |
42 | 41 | | |
43 | | - | |
44 | 42 | | |
45 | 43 | | |
46 | | - | |
47 | 44 | | |
48 | | - | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
49 | 48 | | |
50 | | - | |
51 | | - | |
52 | | - | |
| 49 | + | |
53 | 50 | | |
54 | 51 | | |
55 | 52 | | |
| |||
60 | 57 | | |
61 | 58 | | |
62 | 59 | | |
63 | | - | |
64 | 60 | | |
65 | 61 | | |
66 | 62 | | |
| |||
69 | 65 | | |
70 | 66 | | |
71 | 67 | | |
72 | | - | |
73 | 68 | | |
74 | 69 | | |
75 | 70 | | |
76 | | - | |
77 | 71 | | |
78 | 72 | | |
79 | 73 | | |
80 | | - | |
| 74 | + | |
81 | 75 | | |
| 76 | + | |
| 77 | + | |
82 | 78 | | |
83 | 79 | | |
84 | 80 | | |
85 | 81 | | |
86 | | - | |
87 | | - | |
88 | | - | |
| 82 | + | |
89 | 83 | | |
90 | 84 | | |
91 | 85 | | |
0 commit comments