Incremental text output and asynchronous execution are two different choices. For a CometAPI chat integration through LiteLLM, choose the stream consumer to match the code that will own it—not simply because the UI needs to display text as it arrives.
The LiteLLM CometAPI provider guide documents two paths:
| Application path | Request pattern | Consumption pattern |
|---|---|---|
| Synchronous code | completion(..., stream=True) |
for chunk in response |
| Coroutine-based code | await acompletion(..., stream=True) |
async for chunk in response |
Both are streaming examples. The second changes the call and iteration protocol; it is not evidence of faster model responses.
First, keep the CometAPI configuration route straight
LiteLLM’s dedicated provider guide uses COMETAPI_KEY and a cometapi/ prefix on the model string. It also documents passing the key explicitly through api_key. Supply the credential securely rather than putting a real key in a source file.
There is a separate recipe in CometAPI’s official documentation: its “Start in minutes” Python example constructs an OpenAI SDK client with api_key read from COMETAPI_KEY and base_url="https://api.cometapi.com/v1", then uses a <MODEL_ID> placeholder.
That distinction matters when adapting an existing CometAPI client. If you choose LiteLLM’s dedicated provider path, follow its provider-prefixed model recipe. If you stay with the SDK client, follow the official endpoint/client configuration. Do not assume that moving the model string or configuration between those recipes is sufficient to preserve behavior. The official quick-start establishes the SDK configuration, not LiteLLM’s stream-consumption contract.
Then choose the consumer
For synchronous application code, the guide’s “Usage - Streaming” section calls completion with stream=True and loops over the result with an ordinary for. Its text-output step is:
print(chunk.choices[0].delta.content or "", end="")
The empty-string fallback is part of that example. It is not a complete renderer for every possible chunk shape.
For a coroutine-based handler, follow “Usage - Async Streaming”: await acompletion(..., stream=True), then consume the returned response with async for. Changing only for to async for would miss the documented change to the request function and its awaited call.
There is also an output difference worth catching before copying the example: the async guide prints whole chunks, whereas the synchronous example extracts text deltas. Treat the async example as a control-flow demonstration, not a finished text UI adapter.
A bounded implementation check
Before wiring this into a chat view:
- Decide whether the caller owns a synchronous path or a coroutine-based path.
- Keep the selected CometAPI client/provider configuration consistent with that path’s documentation.
- Confirm the intended model’s availability and streaming behavior, then inspect its actual chunks before choosing a text-rendering step.
The provider guide uses cometapi/gpt-5.6-terra in its examples. That is a documented example identifier here, not a verified availability claim or evidence that every CometAPI model supports streaming.
These are documentation-derived integration choices, not results from an executed integration. Neither cited example establishes concurrency gains, cancellation behavior, backpressure handling, or production reliability. The useful decision is narrower: pick the documented call-and-iterator pair that fits the application, while keeping the CometAPI provider route explicit.