Skip to main content

OpenAPI 3.1 tool server for iFlow Search (心流搜索) — drop-in for Open WebUI, Coze, and other platforms that consume OpenAPI tool catalogues.

Project description

iflow-search-openapi

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.

Install

pip install --pre iflow-search-openapi

--pre is required while the version is still a PEP 440 prerelease.

Run

export IFLOW_API_KEY="your-iflow-api-key"
iflow-search-openapi

Output (stderr):

[iflow-search-openapi] v0.1.0a0 listening on http://127.0.0.1:8787 — bearer auth DISABLED (open mode)

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 for the full env list.

Endpoints

Method Path Description
GET /health Liveness probe — {"ok": true, "version": "..."}
GET /openapi.json OpenAPI 3.1 schema (auto-generated from Pydantic models)
POST /tools/iflow_web_search {"query": "...", "count": 3}
POST /tools/iflow_image_search {"query": "...", "count": 3}
POST /tools/iflow_web_fetch {"url": "https://example.com"}

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.

Success envelope

{
  "ok": true,
  "data": {
    "query": "latest LLM benchmarks",
    "results": [
      {"title": "...", "url": "https://...", "snippet": "...", "position": 1}
    ],
    "took_ms": 142
  }
}

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.

Error envelope

{
  "ok": false,
  "error": {
    "code": "business_rate_limited",
    "message": "Rate limit exceeded.",
    "status_code": 429
  }
}

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.

Use with Open WebUI

  1. Run iflow-search-openapi somewhere Open WebUI can reach.
    • Same host as Open WebUI: defaults are fine.
    • 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.
  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.
  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.
  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).

If Open WebUI runs in a browser on a different origin from this server, set IFLOW_OPENAPI_CORS_ORIGIN=https://your-open-webui-host.

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.

Use with Coze

  1. Run iflow-search-openapi somewhere Coze can reach.
  2. Coze → Plugins → Create plugin → Import from OpenAPI → URL http://your-host:8787/openapi.json.
  3. Provide the bearer token (IFLOW_OPENAPI_AUTH_TOKEN) when prompted.
  4. The three tools appear as plugin actions; attach to a bot as usual.

Authentication

Two distinct credentials:

Credential Direction Source
IFLOW_API_KEY this server → iFlow API env, required
IFLOW_OPENAPI_AUTH_TOKEN external client → this server env, optional

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.

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.

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.

Configuration

All configuration is via environment variables. No .env loader. No CLI flags. No config file.

Variable Required Default Notes
IFLOW_API_KEY yes iFlow API key. Read once at startup, never echoed.
IFLOW_BASE_URL no core default Override iFlow API base URL (staging/proxy).
IFLOW_TIMEOUT_MS no 30000 Per-request timeout in milliseconds.
IFLOW_OPENAPI_HOST no 127.0.0.1 Bind address. Use 0.0.0.0 for LAN/container exposure.
IFLOW_OPENAPI_PORT no 8787 Bind port.
IFLOW_OPENAPI_AUTH_TOKEN no unset (open mode) Bearer token required from external callers when set.
IFLOW_OPENAPI_CORS_ORIGIN no unset (no CORS) * or an exact origin (https://host[:port]).
IFLOW_OPENAPI_CLIENT no unset Free-form host name (e.g. open-webui). Banner only — not on the wire.

Heroku / App Engine / fly.io — bridging PORT

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:

IFLOW_OPENAPI_PORT="$PORT" IFLOW_OPENAPI_HOST=0.0.0.0 iflow-search-openapi

CORS

IFLOW_OPENAPI_CORS_ORIGIN:

  • unset — no CORS headers; server is intended for same-origin or server-to-server use.
  • * — wildcard allow-origin.
  • http(s)://host[:port] — exact-origin allow.

Anything with a path, query, fragment, or non-printable character is rejected at startup with ConfigError and exit code 1 — header-injection guard.

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.

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.

Attribution

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:

Header Value
Authorization Bearer <IFLOW_API_KEY>
IFlow-Source openapi
IFlow-Integration iflow-search-openapi
IFlow-Integration-Version this package's __version__
User-Agent iflow-search-openapi/<version>

IFLOW_OPENAPI_CLIENT is not forwarded as a wire header (that namespace belongs to MCP transports). It appears in the startup banner only.

What's not included in v0.1.0a0

  • TLS termination — put a reverse proxy in front.
  • Streaming / SSE / WebSocket — iFlow Search is request/response.
  • Per-platform packages (no iflow-search-open-webui, no iflow-search-coze).
  • A public Python embedding API (build_app(...) is underscore-prefixed and not part of the contract).
  • .env file loading, a CLI flag for the API key, or any config file.
  • Per-request access logs — operators put a reverse proxy in front for those.

Public Python surface

from iflow_search_openapi import __version__

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.

Local development

From packages/iflow-search-openapi/:

python -m pip install -e ".[dev]"
python -m pytest -q
python -m ruff check .
python -m mypy src/iflow_search_openapi
python -m build

Real-API smoke

cd packages/iflow-search-openapi
export IFLOW_API_KEY="your-api-key"
export IFLOW_OPENAPI_SMOKE=1
python scripts/smoke_real_api.py

The script:

  • Is opt-in — without IFLOW_OPENAPI_SMOKE=1 it refuses to call the live API.
  • Reads IFLOW_API_KEY from the environment only — never from disk.
  • Redacts the key in all log output.
  • Does not write any file.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

iflow_search_openapi-0.1.0a2.tar.gz (19.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

iflow_search_openapi-0.1.0a2-py3-none-any.whl (25.7 kB view details)

Uploaded Python 3

File details

Details for the file iflow_search_openapi-0.1.0a2.tar.gz.

File metadata

  • Download URL: iflow_search_openapi-0.1.0a2.tar.gz
  • Upload date:
  • Size: 19.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for iflow_search_openapi-0.1.0a2.tar.gz
Algorithm Hash digest
SHA256 153fd5fe23c387234c58ee9bf125e7d7c99d6e1c7f61844cc7da38bde28227d5
MD5 a26274814e682468ba2f9f39ff39410e
BLAKE2b-256 490060659ed10d5275d4123e0b8f0f661b9c735f7abb47926f2947f4967c0fb1

See more details on using hashes here.

File details

Details for the file iflow_search_openapi-0.1.0a2-py3-none-any.whl.

File metadata

File hashes

Hashes for iflow_search_openapi-0.1.0a2-py3-none-any.whl
Algorithm Hash digest
SHA256 db8056bdb74f10b891db09d36be4aadd9286f4f46c1219b630c57173aba3c20e
MD5 b79f61b21b9fc3f273d79814257fa58a
BLAKE2b-256 01b620625b496e33db24596cf474560d911a46ec8b85859999055f31aa2db3d4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page