Guides
Model Adapters
Adapt upstream protocols once through AIChannel.stream().
Downcity has one core model protocol. OpenAI Chat Completions is adapted only at the HTTP boundary:
City SDK / CityModel ------\
-> ModelCall -> AIService -> AIChannel.stream()
OpenAI Chat Completions ---/ -> ModelStreamEventUse stream_openai_compatible_model() for an OpenAI-compatible upstream. For a private HTTP protocol, provide an Adapter that maps ModelCall into the vendor request and returns AIChannelStreamResult. AIService does not know the vendor request format.
OpenAI Chat Completions is an HTTP Adapter around the same Model Protocol path. There is no raw passthrough and no second model execution path, so tools, fallback, reasoning, metering, and billing behave consistently across clients.
Keep upstream-specific behavior in the Channel:
- credentials and base URL;
- upstream model factory and protocol selection;
- model-specific
provider_options; - usage interpretation and billing;
- conversion from private streams to
ModelStreamEvent.
Keep Federation behavior in AIService:
- model registry and public catalog;
- authentication and availability;
- media fallback and reasoning validation;
- metering, balance checks, and charge settlement.