iflow-search-openapi 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,47 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ *.so
6
+ .Python
7
+ .pytest_cache/
8
+ .mypy_cache/
9
+ .ruff_cache/
10
+ .coverage
11
+ .coverage.*
12
+ htmlcov/
13
+ *.egg-info/
14
+ *.egg
15
+
16
+ # Build artifacts
17
+ build/
18
+ dist/
19
+ *.whl
20
+ *.tar.gz
21
+
22
+ # Virtual environments
23
+ .venv/
24
+ venv/
25
+ env/
26
+ ENV/
27
+
28
+ # Editor / OS
29
+ .vscode/
30
+ .idea/
31
+ .DS_Store
32
+ *.swp
33
+
34
+ # Secrets — never commit
35
+ .env
36
+ .env.*
37
+ *.pem
38
+ *.key
39
+ api-keys.env
40
+
41
+ # uv
42
+ .uv/
43
+ uv.lock
44
+
45
+ # Local Claude Code working instructions — not for the public repo
46
+ CLAUDE.md
47
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 iFlow Search SDK contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,269 @@
1
+ Metadata-Version: 2.4
2
+ Name: iflow-search-openapi
3
+ Version: 0.1.0
4
+ Summary: OpenAPI 3.1 tool server for iFlow Search (心流搜索) — drop-in for Open WebUI, Coze, and other platforms that consume OpenAPI tool catalogues.
5
+ Project-URL: Homepage, https://platform.iflow.cn/
6
+ Project-URL: Documentation, https://platform.iflow.cn/docs/
7
+ Project-URL: Repository, https://github.com/zhengyanglsun/iflow-search-py
8
+ Project-URL: Issues, https://github.com/zhengyanglsun/iflow-search-py/issues
9
+ Author: iFlow Search SDK contributors
10
+ License: MIT License
11
+
12
+ Copyright (c) 2026 iFlow Search SDK contributors
13
+
14
+ Permission is hereby granted, free of charge, to any person obtaining a copy
15
+ of this software and associated documentation files (the "Software"), to deal
16
+ in the Software without restriction, including without limitation the rights
17
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18
+ copies of the Software, and to permit persons to whom the Software is
19
+ furnished to do so, subject to the following conditions:
20
+
21
+ The above copyright notice and this permission notice shall be included in all
22
+ copies or substantial portions of the Software.
23
+
24
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30
+ SOFTWARE.
31
+ License-File: LICENSE
32
+ Keywords: ai,coze,iflow,llm,open-webui,openapi,search,tools
33
+ Classifier: Development Status :: 4 - Beta
34
+ Classifier: Framework :: FastAPI
35
+ Classifier: Intended Audience :: Developers
36
+ Classifier: License :: OSI Approved :: MIT License
37
+ Classifier: Operating System :: OS Independent
38
+ Classifier: Programming Language :: Python
39
+ Classifier: Programming Language :: Python :: 3
40
+ Classifier: Programming Language :: Python :: 3.10
41
+ Classifier: Programming Language :: Python :: 3.11
42
+ Classifier: Programming Language :: Python :: 3.12
43
+ Classifier: Programming Language :: Python :: 3.13
44
+ Classifier: Topic :: Internet :: WWW/HTTP
45
+ Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
46
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
47
+ Classifier: Typing :: Typed
48
+ Requires-Python: >=3.10
49
+ Requires-Dist: fastapi<1.0,>=0.115
50
+ Requires-Dist: iflow-search<0.2,>=0.1.0
51
+ Requires-Dist: pydantic<3.0,>=2.7
52
+ Requires-Dist: uvicorn<1.0,>=0.30
53
+ Provides-Extra: dev
54
+ Requires-Dist: httpx<1.0,>=0.27; extra == 'dev'
55
+ Requires-Dist: mypy>=1.10; extra == 'dev'
56
+ Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
57
+ Requires-Dist: pytest>=8; extra == 'dev'
58
+ Requires-Dist: ruff>=0.4; extra == 'dev'
59
+ Requires-Dist: tomli>=2.0; (python_version < '3.11') and extra == 'dev'
60
+ Description-Content-Type: text/markdown
61
+
62
+ # iflow-search-openapi
63
+
64
+ OpenAPI 3.1 tool server for **iFlow Search (心流搜索)** — exposes `iflow_web_search`, `iflow_image_search`, and `iflow_web_fetch` over plain HTTP so platforms that consume OpenAPI tool catalogues (Open WebUI, Coze, …) can wire them in directly.
65
+
66
+ - **Core SDK:** [`iflow-search`](https://pypi.org/project/iflow-search/) — this package wraps it; do not skip installing it (it is a transitive dependency, so `pip install` handles it).
67
+ - **Sibling adapters:** [`iflow-search-mcp`](https://pypi.org/project/iflow-search-mcp/) (MCP stdio server), [`iflow-search-langchain`](https://pypi.org/project/iflow-search-langchain/) (LangChain tools).
68
+ - **API docs:** <https://platform.iflow.cn/docs/>
69
+ - **Status:** stable (`0.1.0`).
70
+
71
+ ## Install
72
+
73
+ ```bash
74
+ pip install iflow-search-openapi
75
+ ```
76
+
77
+ ## Run
78
+
79
+ ```bash
80
+ export IFLOW_API_KEY="your-iflow-api-key"
81
+ iflow-search-openapi
82
+ ```
83
+
84
+ Output (stderr):
85
+
86
+ ```
87
+ [iflow-search-openapi] v0.1.0 listening on http://127.0.0.1:8787 — bearer auth DISABLED (open mode)
88
+ ```
89
+
90
+ By default the server binds **`127.0.0.1:8787`** — local-only. Set `IFLOW_OPENAPI_HOST=0.0.0.0` to expose it to a LAN or a container network. See [Configuration](#configuration) for the full env list.
91
+
92
+ ## Endpoints
93
+
94
+ | Method | Path | Description |
95
+ |---|---|---|
96
+ | `GET` | `/health` | Liveness probe — `{"ok": true, "version": "..."}` |
97
+ | `GET` | `/openapi.json` | OpenAPI 3.1 schema (auto-generated from Pydantic models) |
98
+ | `POST` | `/tools/iflow_web_search` | `{"query": "...", "count": 3}` |
99
+ | `POST` | `/tools/iflow_image_search` | `{"query": "...", "count": 3}` |
100
+ | `POST` | `/tools/iflow_web_fetch` | `{"url": "https://example.com"}` |
101
+
102
+ Each tool route declares an explicit OpenAPI `operationId` matching its path-level name (`iflow_web_search`, `iflow_image_search`, `iflow_web_fetch`). Tool hosts such as Open WebUI and Coze dispatch by `operationId` and surface it as the tool name to the consuming LLM — pinning them keeps the LLM-facing names stable across releases.
103
+
104
+ ### Success envelope
105
+
106
+ ```json
107
+ {
108
+ "ok": true,
109
+ "data": {
110
+ "query": "latest LLM benchmarks",
111
+ "results": [
112
+ {"title": "...", "url": "https://...", "snippet": "...", "position": 1}
113
+ ],
114
+ "took_ms": 142
115
+ }
116
+ }
117
+ ```
118
+
119
+ Field names are **snake_case**. The core SDK's `raw` (upstream envelope) is excluded by default — it bloats LLM context for fields the model cannot act on.
120
+
121
+ ### Error envelope
122
+
123
+ ```json
124
+ {
125
+ "ok": false,
126
+ "error": {
127
+ "code": "business_rate_limited",
128
+ "message": "Rate limit exceeded.",
129
+ "status_code": 429
130
+ }
131
+ }
132
+ ```
133
+
134
+ `code` is a stable string; switch on it (not on HTTP status alone) for retry/backoff decisions. The full code table is in [`docs/design/python-openapi-design.md` §8.3](https://github.com/zhengyanglsun/iflow-search-py/blob/main/docs/design/python-openapi-design.md).
135
+
136
+ ## Use with Open WebUI
137
+
138
+ 1. Run `iflow-search-openapi` somewhere Open WebUI can reach.
139
+ - Same host as Open WebUI: defaults are fine.
140
+ - Open WebUI in Docker, this server on the host: bind with `IFLOW_OPENAPI_HOST=0.0.0.0` and use `http://host.docker.internal:<port>` from inside the container.
141
+ 2. In Open WebUI → **Settings → Admin Settings → Tools → External Tool Servers → Add Connection**, paste the server URL (e.g. `http://host.docker.internal:8787`). The path defaults to `openapi.json`.
142
+ 3. If you set `IFLOW_OPENAPI_AUTH_TOKEN`, choose **Bearer** auth and paste the token. Otherwise leave auth as **None** — the server is open, exactly as configured.
143
+ 4. Open WebUI fetches `/openapi.json` and registers the three tools. They appear as `iflow_web_search`, `iflow_image_search`, `iflow_web_fetch` in the model's tool list (matching the explicit `operationId` values).
144
+
145
+ If Open WebUI runs in a browser on a different origin from this server, set `IFLOW_OPENAPI_CORS_ORIGIN=https://your-open-webui-host`.
146
+
147
+ The same registration can be driven over HTTP for headless setups — POST to `/api/v1/configs/tool_servers` on Open WebUI with a `TOOL_SERVER_CONNECTIONS` payload mirroring the UI fields above.
148
+
149
+ ## Use with Coze
150
+
151
+ 1. Run `iflow-search-openapi` somewhere Coze can reach.
152
+ 2. Coze → **Plugins → Create plugin → Import from OpenAPI** → URL `http://your-host:8787/openapi.json`.
153
+ 3. Provide the bearer token (`IFLOW_OPENAPI_AUTH_TOKEN`) when prompted.
154
+ 4. The three tools appear as plugin actions; attach to a bot as usual.
155
+
156
+ ## Authentication
157
+
158
+ Two distinct credentials:
159
+
160
+ | Credential | Direction | Source |
161
+ |---|---|---|
162
+ | `IFLOW_API_KEY` | this server → iFlow API | env, required |
163
+ | `IFLOW_OPENAPI_AUTH_TOKEN` | external client → this server | env, optional |
164
+
165
+ When `IFLOW_OPENAPI_AUTH_TOKEN` is **unset**, the server is open: any caller that can reach the socket can invoke the tools. Intended for local dev or behind a private network / reverse proxy.
166
+
167
+ When **set**, all routes except `/health` require `Authorization: Bearer <token>`. The compare is constant-time. `/openapi.json` is also gated so the schema (which advertises the server as an iFlow proxy) stays behind the bearer.
168
+
169
+ `IFLOW_API_KEY` is **never** echoed in any response, log line, OpenAPI schema, or startup banner — only its *presence* is implied by the server having started successfully.
170
+
171
+ ## Configuration
172
+
173
+ All configuration is via environment variables. **No `.env` loader. No CLI flags. No config file.**
174
+
175
+ | Variable | Required | Default | Notes |
176
+ |---|---|---|---|
177
+ | `IFLOW_API_KEY` | yes | — | iFlow API key. Read once at startup, never echoed. |
178
+ | `IFLOW_BASE_URL` | no | core default | Override iFlow API base URL (staging/proxy). |
179
+ | `IFLOW_TIMEOUT_MS` | no | `30000` | Per-request timeout in milliseconds. |
180
+ | `IFLOW_OPENAPI_HOST` | no | `127.0.0.1` | Bind address. Use `0.0.0.0` for LAN/container exposure. |
181
+ | `IFLOW_OPENAPI_PORT` | no | `8787` | Bind port. |
182
+ | `IFLOW_OPENAPI_AUTH_TOKEN` | no | unset (open mode) | Bearer token required from external callers when set. |
183
+ | `IFLOW_OPENAPI_CORS_ORIGIN` | no | unset (no CORS) | `*` or an exact origin (`https://host[:port]`). |
184
+ | `IFLOW_OPENAPI_CLIENT` | no | unset | Free-form host name (e.g. `open-webui`). Banner only — not on the wire. |
185
+
186
+ ### Heroku / App Engine / fly.io — bridging `PORT`
187
+
188
+ This package uses `IFLOW_OPENAPI_PORT` instead of the generic `PORT` so a platform's auto-injected port can't silently take over the bind. If your platform requires `PORT`, bridge it in your start command:
189
+
190
+ ```bash
191
+ IFLOW_OPENAPI_PORT="$PORT" IFLOW_OPENAPI_HOST=0.0.0.0 iflow-search-openapi
192
+ ```
193
+
194
+ ## CORS
195
+
196
+ `IFLOW_OPENAPI_CORS_ORIGIN`:
197
+
198
+ - **unset** — no CORS headers; server is intended for same-origin or server-to-server use.
199
+ - `*` — wildcard allow-origin.
200
+ - `http(s)://host[:port]` — exact-origin allow.
201
+
202
+ Anything with a path, query, fragment, or non-printable character is rejected at startup with `ConfigError` and exit code 1 — header-injection guard.
203
+
204
+ Preflight (`OPTIONS`) short-circuits before the bearer check and returns HTTP 200 with the correct `Access-Control-Allow-*` headers, so browser-side tool importers (Open WebUI) can complete preflight without a token.
205
+
206
+ `Access-Control-Allow-Headers` is `Content-Type, Authorization, X-Session-Id`. `X-Session-Id` is allowed for Open WebUI compatibility; the adapter does not read it.
207
+
208
+ ## Attribution
209
+
210
+ The adapter does not construct any `Authorization`, `IFlow-*`, or `User-Agent` header itself — that's the core SDK's job. Outbound requests to iFlow carry:
211
+
212
+ | Header | Value |
213
+ |---|---|
214
+ | `Authorization` | `Bearer <IFLOW_API_KEY>` |
215
+ | `IFlow-Source` | `openapi` |
216
+ | `IFlow-Integration` | `iflow-search-openapi` |
217
+ | `IFlow-Integration-Version` | this package's `__version__` |
218
+ | `User-Agent` | `iflow-search-openapi/<version>` |
219
+
220
+ `IFLOW_OPENAPI_CLIENT` is **not** forwarded as a wire header (that namespace belongs to MCP transports). It appears in the startup banner only.
221
+
222
+ ## What's not included in this release
223
+
224
+ - TLS termination — put a reverse proxy in front.
225
+ - Streaming / SSE / WebSocket — iFlow Search is request/response.
226
+ - Per-platform packages (no `iflow-search-open-webui`, no `iflow-search-coze`).
227
+ - A public Python embedding API (`build_app(...)` is underscore-prefixed and not part of the contract).
228
+ - `.env` file loading, a CLI flag for the API key, or any config file.
229
+ - Per-request access logs — operators put a reverse proxy in front for those.
230
+
231
+ ## Public Python surface
232
+
233
+ ```python
234
+ from iflow_search_openapi import __version__
235
+ ```
236
+
237
+ That is the only supported import in MVP. Internal modules (`_app`, `_routes`, `_auth`, etc.) are underscore-prefixed; they may be reorganised without notice. The stable contract is the **HTTP surface**, not the Python surface.
238
+
239
+ ## Local development
240
+
241
+ From `packages/iflow-search-openapi/`:
242
+
243
+ ```bash
244
+ python -m pip install -e ".[dev]"
245
+ python -m pytest -q
246
+ python -m ruff check .
247
+ python -m mypy src/iflow_search_openapi
248
+ python -m build
249
+ ```
250
+
251
+ ## Real-API smoke
252
+
253
+ ```bash
254
+ cd packages/iflow-search-openapi
255
+ export IFLOW_API_KEY="your-api-key"
256
+ export IFLOW_OPENAPI_SMOKE=1
257
+ python scripts/smoke_real_api.py
258
+ ```
259
+
260
+ The script:
261
+
262
+ - Is **opt-in** — without `IFLOW_OPENAPI_SMOKE=1` it refuses to call the live API.
263
+ - Reads `IFLOW_API_KEY` from the environment only — never from disk.
264
+ - Redacts the key in all log output.
265
+ - Does not write any file.
266
+
267
+ ## License
268
+
269
+ [MIT](./LICENSE)
@@ -0,0 +1,208 @@
1
+ # iflow-search-openapi
2
+
3
+ OpenAPI 3.1 tool server for **iFlow Search (心流搜索)** — exposes `iflow_web_search`, `iflow_image_search`, and `iflow_web_fetch` over plain HTTP so platforms that consume OpenAPI tool catalogues (Open WebUI, Coze, …) can wire them in directly.
4
+
5
+ - **Core SDK:** [`iflow-search`](https://pypi.org/project/iflow-search/) — this package wraps it; do not skip installing it (it is a transitive dependency, so `pip install` handles it).
6
+ - **Sibling adapters:** [`iflow-search-mcp`](https://pypi.org/project/iflow-search-mcp/) (MCP stdio server), [`iflow-search-langchain`](https://pypi.org/project/iflow-search-langchain/) (LangChain tools).
7
+ - **API docs:** <https://platform.iflow.cn/docs/>
8
+ - **Status:** stable (`0.1.0`).
9
+
10
+ ## Install
11
+
12
+ ```bash
13
+ pip install iflow-search-openapi
14
+ ```
15
+
16
+ ## Run
17
+
18
+ ```bash
19
+ export IFLOW_API_KEY="your-iflow-api-key"
20
+ iflow-search-openapi
21
+ ```
22
+
23
+ Output (stderr):
24
+
25
+ ```
26
+ [iflow-search-openapi] v0.1.0 listening on http://127.0.0.1:8787 — bearer auth DISABLED (open mode)
27
+ ```
28
+
29
+ By default the server binds **`127.0.0.1:8787`** — local-only. Set `IFLOW_OPENAPI_HOST=0.0.0.0` to expose it to a LAN or a container network. See [Configuration](#configuration) for the full env list.
30
+
31
+ ## Endpoints
32
+
33
+ | Method | Path | Description |
34
+ |---|---|---|
35
+ | `GET` | `/health` | Liveness probe — `{"ok": true, "version": "..."}` |
36
+ | `GET` | `/openapi.json` | OpenAPI 3.1 schema (auto-generated from Pydantic models) |
37
+ | `POST` | `/tools/iflow_web_search` | `{"query": "...", "count": 3}` |
38
+ | `POST` | `/tools/iflow_image_search` | `{"query": "...", "count": 3}` |
39
+ | `POST` | `/tools/iflow_web_fetch` | `{"url": "https://example.com"}` |
40
+
41
+ Each tool route declares an explicit OpenAPI `operationId` matching its path-level name (`iflow_web_search`, `iflow_image_search`, `iflow_web_fetch`). Tool hosts such as Open WebUI and Coze dispatch by `operationId` and surface it as the tool name to the consuming LLM — pinning them keeps the LLM-facing names stable across releases.
42
+
43
+ ### Success envelope
44
+
45
+ ```json
46
+ {
47
+ "ok": true,
48
+ "data": {
49
+ "query": "latest LLM benchmarks",
50
+ "results": [
51
+ {"title": "...", "url": "https://...", "snippet": "...", "position": 1}
52
+ ],
53
+ "took_ms": 142
54
+ }
55
+ }
56
+ ```
57
+
58
+ Field names are **snake_case**. The core SDK's `raw` (upstream envelope) is excluded by default — it bloats LLM context for fields the model cannot act on.
59
+
60
+ ### Error envelope
61
+
62
+ ```json
63
+ {
64
+ "ok": false,
65
+ "error": {
66
+ "code": "business_rate_limited",
67
+ "message": "Rate limit exceeded.",
68
+ "status_code": 429
69
+ }
70
+ }
71
+ ```
72
+
73
+ `code` is a stable string; switch on it (not on HTTP status alone) for retry/backoff decisions. The full code table is in [`docs/design/python-openapi-design.md` §8.3](https://github.com/zhengyanglsun/iflow-search-py/blob/main/docs/design/python-openapi-design.md).
74
+
75
+ ## Use with Open WebUI
76
+
77
+ 1. Run `iflow-search-openapi` somewhere Open WebUI can reach.
78
+ - Same host as Open WebUI: defaults are fine.
79
+ - Open WebUI in Docker, this server on the host: bind with `IFLOW_OPENAPI_HOST=0.0.0.0` and use `http://host.docker.internal:<port>` from inside the container.
80
+ 2. In Open WebUI → **Settings → Admin Settings → Tools → External Tool Servers → Add Connection**, paste the server URL (e.g. `http://host.docker.internal:8787`). The path defaults to `openapi.json`.
81
+ 3. If you set `IFLOW_OPENAPI_AUTH_TOKEN`, choose **Bearer** auth and paste the token. Otherwise leave auth as **None** — the server is open, exactly as configured.
82
+ 4. Open WebUI fetches `/openapi.json` and registers the three tools. They appear as `iflow_web_search`, `iflow_image_search`, `iflow_web_fetch` in the model's tool list (matching the explicit `operationId` values).
83
+
84
+ If Open WebUI runs in a browser on a different origin from this server, set `IFLOW_OPENAPI_CORS_ORIGIN=https://your-open-webui-host`.
85
+
86
+ The same registration can be driven over HTTP for headless setups — POST to `/api/v1/configs/tool_servers` on Open WebUI with a `TOOL_SERVER_CONNECTIONS` payload mirroring the UI fields above.
87
+
88
+ ## Use with Coze
89
+
90
+ 1. Run `iflow-search-openapi` somewhere Coze can reach.
91
+ 2. Coze → **Plugins → Create plugin → Import from OpenAPI** → URL `http://your-host:8787/openapi.json`.
92
+ 3. Provide the bearer token (`IFLOW_OPENAPI_AUTH_TOKEN`) when prompted.
93
+ 4. The three tools appear as plugin actions; attach to a bot as usual.
94
+
95
+ ## Authentication
96
+
97
+ Two distinct credentials:
98
+
99
+ | Credential | Direction | Source |
100
+ |---|---|---|
101
+ | `IFLOW_API_KEY` | this server → iFlow API | env, required |
102
+ | `IFLOW_OPENAPI_AUTH_TOKEN` | external client → this server | env, optional |
103
+
104
+ When `IFLOW_OPENAPI_AUTH_TOKEN` is **unset**, the server is open: any caller that can reach the socket can invoke the tools. Intended for local dev or behind a private network / reverse proxy.
105
+
106
+ When **set**, all routes except `/health` require `Authorization: Bearer <token>`. The compare is constant-time. `/openapi.json` is also gated so the schema (which advertises the server as an iFlow proxy) stays behind the bearer.
107
+
108
+ `IFLOW_API_KEY` is **never** echoed in any response, log line, OpenAPI schema, or startup banner — only its *presence* is implied by the server having started successfully.
109
+
110
+ ## Configuration
111
+
112
+ All configuration is via environment variables. **No `.env` loader. No CLI flags. No config file.**
113
+
114
+ | Variable | Required | Default | Notes |
115
+ |---|---|---|---|
116
+ | `IFLOW_API_KEY` | yes | — | iFlow API key. Read once at startup, never echoed. |
117
+ | `IFLOW_BASE_URL` | no | core default | Override iFlow API base URL (staging/proxy). |
118
+ | `IFLOW_TIMEOUT_MS` | no | `30000` | Per-request timeout in milliseconds. |
119
+ | `IFLOW_OPENAPI_HOST` | no | `127.0.0.1` | Bind address. Use `0.0.0.0` for LAN/container exposure. |
120
+ | `IFLOW_OPENAPI_PORT` | no | `8787` | Bind port. |
121
+ | `IFLOW_OPENAPI_AUTH_TOKEN` | no | unset (open mode) | Bearer token required from external callers when set. |
122
+ | `IFLOW_OPENAPI_CORS_ORIGIN` | no | unset (no CORS) | `*` or an exact origin (`https://host[:port]`). |
123
+ | `IFLOW_OPENAPI_CLIENT` | no | unset | Free-form host name (e.g. `open-webui`). Banner only — not on the wire. |
124
+
125
+ ### Heroku / App Engine / fly.io — bridging `PORT`
126
+
127
+ This package uses `IFLOW_OPENAPI_PORT` instead of the generic `PORT` so a platform's auto-injected port can't silently take over the bind. If your platform requires `PORT`, bridge it in your start command:
128
+
129
+ ```bash
130
+ IFLOW_OPENAPI_PORT="$PORT" IFLOW_OPENAPI_HOST=0.0.0.0 iflow-search-openapi
131
+ ```
132
+
133
+ ## CORS
134
+
135
+ `IFLOW_OPENAPI_CORS_ORIGIN`:
136
+
137
+ - **unset** — no CORS headers; server is intended for same-origin or server-to-server use.
138
+ - `*` — wildcard allow-origin.
139
+ - `http(s)://host[:port]` — exact-origin allow.
140
+
141
+ Anything with a path, query, fragment, or non-printable character is rejected at startup with `ConfigError` and exit code 1 — header-injection guard.
142
+
143
+ Preflight (`OPTIONS`) short-circuits before the bearer check and returns HTTP 200 with the correct `Access-Control-Allow-*` headers, so browser-side tool importers (Open WebUI) can complete preflight without a token.
144
+
145
+ `Access-Control-Allow-Headers` is `Content-Type, Authorization, X-Session-Id`. `X-Session-Id` is allowed for Open WebUI compatibility; the adapter does not read it.
146
+
147
+ ## Attribution
148
+
149
+ The adapter does not construct any `Authorization`, `IFlow-*`, or `User-Agent` header itself — that's the core SDK's job. Outbound requests to iFlow carry:
150
+
151
+ | Header | Value |
152
+ |---|---|
153
+ | `Authorization` | `Bearer <IFLOW_API_KEY>` |
154
+ | `IFlow-Source` | `openapi` |
155
+ | `IFlow-Integration` | `iflow-search-openapi` |
156
+ | `IFlow-Integration-Version` | this package's `__version__` |
157
+ | `User-Agent` | `iflow-search-openapi/<version>` |
158
+
159
+ `IFLOW_OPENAPI_CLIENT` is **not** forwarded as a wire header (that namespace belongs to MCP transports). It appears in the startup banner only.
160
+
161
+ ## What's not included in this release
162
+
163
+ - TLS termination — put a reverse proxy in front.
164
+ - Streaming / SSE / WebSocket — iFlow Search is request/response.
165
+ - Per-platform packages (no `iflow-search-open-webui`, no `iflow-search-coze`).
166
+ - A public Python embedding API (`build_app(...)` is underscore-prefixed and not part of the contract).
167
+ - `.env` file loading, a CLI flag for the API key, or any config file.
168
+ - Per-request access logs — operators put a reverse proxy in front for those.
169
+
170
+ ## Public Python surface
171
+
172
+ ```python
173
+ from iflow_search_openapi import __version__
174
+ ```
175
+
176
+ That is the only supported import in MVP. Internal modules (`_app`, `_routes`, `_auth`, etc.) are underscore-prefixed; they may be reorganised without notice. The stable contract is the **HTTP surface**, not the Python surface.
177
+
178
+ ## Local development
179
+
180
+ From `packages/iflow-search-openapi/`:
181
+
182
+ ```bash
183
+ python -m pip install -e ".[dev]"
184
+ python -m pytest -q
185
+ python -m ruff check .
186
+ python -m mypy src/iflow_search_openapi
187
+ python -m build
188
+ ```
189
+
190
+ ## Real-API smoke
191
+
192
+ ```bash
193
+ cd packages/iflow-search-openapi
194
+ export IFLOW_API_KEY="your-api-key"
195
+ export IFLOW_OPENAPI_SMOKE=1
196
+ python scripts/smoke_real_api.py
197
+ ```
198
+
199
+ The script:
200
+
201
+ - Is **opt-in** — without `IFLOW_OPENAPI_SMOKE=1` it refuses to call the live API.
202
+ - Reads `IFLOW_API_KEY` from the environment only — never from disk.
203
+ - Redacts the key in all log output.
204
+ - Does not write any file.
205
+
206
+ ## License
207
+
208
+ [MIT](./LICENSE)
@@ -0,0 +1,92 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "iflow-search-openapi"
7
+ version = "0.1.0"
8
+ description = "OpenAPI 3.1 tool server for iFlow Search (心流搜索) — drop-in for Open WebUI, Coze, and other platforms that consume OpenAPI tool catalogues."
9
+ readme = "README.md"
10
+ license = { file = "LICENSE" }
11
+ requires-python = ">=3.10"
12
+ authors = [{ name = "iFlow Search SDK contributors" }]
13
+ keywords = ["iflow", "search", "openapi", "open-webui", "coze", "ai", "llm", "tools"]
14
+ classifiers = [
15
+ "Development Status :: 4 - Beta",
16
+ "Intended Audience :: Developers",
17
+ "License :: OSI Approved :: MIT License",
18
+ "Operating System :: OS Independent",
19
+ "Programming Language :: Python",
20
+ "Programming Language :: Python :: 3",
21
+ "Programming Language :: Python :: 3.10",
22
+ "Programming Language :: Python :: 3.11",
23
+ "Programming Language :: Python :: 3.12",
24
+ "Programming Language :: Python :: 3.13",
25
+ "Framework :: FastAPI",
26
+ "Topic :: Internet :: WWW/HTTP",
27
+ "Topic :: Internet :: WWW/HTTP :: HTTP Servers",
28
+ "Topic :: Software Development :: Libraries :: Python Modules",
29
+ "Typing :: Typed",
30
+ ]
31
+ dependencies = [
32
+ "iflow-search>=0.1.0,<0.2",
33
+ "fastapi>=0.115,<1.0",
34
+ "uvicorn>=0.30,<1.0",
35
+ "pydantic>=2.7,<3.0",
36
+ ]
37
+
38
+ [project.urls]
39
+ Homepage = "https://platform.iflow.cn/"
40
+ Documentation = "https://platform.iflow.cn/docs/"
41
+ Repository = "https://github.com/zhengyanglsun/iflow-search-py"
42
+ Issues = "https://github.com/zhengyanglsun/iflow-search-py/issues"
43
+
44
+ [project.scripts]
45
+ iflow-search-openapi = "iflow_search_openapi._bin:main"
46
+
47
+ [project.optional-dependencies]
48
+ dev = [
49
+ "pytest>=8",
50
+ "pytest-asyncio>=0.23",
51
+ "httpx>=0.27,<1.0",
52
+ "ruff>=0.4",
53
+ "mypy>=1.10",
54
+ "tomli>=2.0; python_version<'3.11'",
55
+ ]
56
+
57
+ [tool.hatch.build.targets.wheel]
58
+ packages = ["src/iflow_search_openapi"]
59
+
60
+ [tool.hatch.build.targets.sdist]
61
+ include = [
62
+ "/src",
63
+ "/README.md",
64
+ "/LICENSE",
65
+ "/pyproject.toml",
66
+ ]
67
+ exclude = [
68
+ "/tests",
69
+ "/scripts",
70
+ "/.pytest_cache",
71
+ "/__pycache__",
72
+ ]
73
+
74
+ [tool.pytest.ini_options]
75
+ minversion = "8.0"
76
+ testpaths = ["tests"]
77
+ asyncio_mode = "strict"
78
+ addopts = "-ra --strict-markers"
79
+
80
+ [tool.ruff]
81
+ line-length = 100
82
+ target-version = "py310"
83
+
84
+ [tool.ruff.lint]
85
+ select = ["E", "F", "W", "I", "UP", "B", "SIM"]
86
+ ignore = ["E501"]
87
+
88
+ [tool.mypy]
89
+ python_version = "3.10"
90
+ strict = true
91
+ warn_unused_ignores = true
92
+ files = ["src/iflow_search_openapi"]
@@ -0,0 +1,12 @@
1
+ """iflow-search-openapi — OpenAPI 3.1 tool server for iFlow Search.
2
+
3
+ Only ``__version__`` is part of the supported public Python surface
4
+ (design §11). All other modules are underscore-prefixed and internal; the
5
+ user-facing entry point is the ``iflow-search-openapi`` console script.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ from ._version import __version__
11
+
12
+ __all__ = ("__version__",)