Expand description
The http transport (CONTEXT.md §8, §14).
One OpenAI-compatible chat client over reqwest, with a configurable base
URL. It covers every OpenAI-format API worker and (in Phase 4) every
conductor backend. Responses are streamed via SSE so deltas reach the event
sink as they arrive, and final token usage is captured.
Structs§
- Chat
Message - A chat message in the OpenAI format. The tool fields are only set on the
host agentic loop:
tool_callson an assistant turn that calls tools,tool_call_idon atool-role message carrying a call’s result. - Chat
Request - A chat completion request.
- Chat
Response - The accumulated result of a (streamed) chat completion.
- Chat
Turn - One turn of the host agentic loop: either text (the model is done) or a set of tool calls to execute and feed back.
- Discovered
Model - A model offered by a platform’s
/v1/modelsendpoint, with optional cost and context metadata where the platform provides it (e.g. OpenRouter). - Function
Call - Open
AiClient - An OpenAI-compatible chat client over a configurable base URL.
- Tool
Call - One tool call in the OpenAI function-calling format — serialized when echoing an assistant turn, deserialized when reading the model’s response.
Traits§
- Chat
Backend - Marker trait tie-in kept minimal for Phase 2; the API worker adapter wraps
this client and implements
Worker.
Functions§
- cloudflare_
account_ id_ from_ base_ url - Extract Cloudflare account id from an OpenAI-compat base URL such as
https://api.cloudflare.com/client/v4/accounts/{id}/ai/v1. - cloudflare_
text_ model_ fallback - Curated Workers AI text model ids (OpenAI-compat chat). Used when the
native models/search API is empty/unavailable so the Models tab still offers
real
@cf/…ids to add. Keep in sync with https://developers.cloudflare.com/workers-ai/models/ - list_
cloudflare_ workers_ ai_ models - Cloudflare Workers AI rejects OpenAI-compatible
GET …/ai/v1/models(HTTP 405). Use the native REST catalog instead:GET /accounts/{account_id}/ai/models/search. - normalize_
base_ url - Normalize an OpenAI-compatible base URL. We append our own path
(
/chat/completions,/models), so a user who pastes a full endpoint URL from a provider’s docs gets it stripped back to the base rather than a doubled path (…/chat/completions/chat/completions→ 404).