Connecting Chinese LLMs to AI Coding Assistants: Why Protocol Compatibility Is the Key

    This article walks through a practical, real-world effort to plug domestic (Chinese) large language models into a modern AI coding assistant. It explains why the core obstacle is not model capability but the mismatch between two incompatible API protocols, why generic "universal proxy" tools tend to fail, and how to build a dedicated protocol adapter layer instead. You will learn how request paths, message structures, parameter names, tool calling, and streaming responses differ, and what it takes to design an adapter that is explicit, maintainable, and ready for upstream changes.

    1. Why bother connecting domestic models to a coding assistant

    Code itself is no longer the barrier—most examples can be regenerated by AI on demand. What is genuinely valuable is the experience of an ordinary developer taking a workable combination from zero to one. This article focuses on one of the most representative pitfalls from that journey.

    It all started with the fact that “getting compute is getting harder.” Early on, many people stitched together usable quotas through various workarounds—third-party account pools, temporary keys, and similar tricks. But as providers kept tightening their risk controls, this path deteriorated quickly:

    • High maintenance cost—something that works today may suddenly stop working tomorrow;
    • Poor stability—it requires constant retries and switching;
    • Unsustainable—it cannot support long-term development.

    Rather than studying how to circumvent risk controls every day, it makes more sense to switch your primary tool to a product with solid context engineering and a good coding experience. The new generation of AI coding tools that appear as “coding assistants” meet exactly this need: they handle codebase understanding, multi-file editing, and tool-call orchestration quite maturely.

    However, these tools usually come with an obvious hard constraint: by default they only call their own bundled models. This creates two practical problems: first, the usage cost is high; second, account registration and maintenance is not easy in itself. As a result, “use a great coding tool but swap in a domestically available, cost-effective model—sometimes even one with a free tier” became a common demand.

    2. The core conflict: the two API protocols are fundamentally incompatible

    The root of the problem lies not in model capability but in the interface protocol.

    These coding tools speak a proprietary API protocol from one vendor, while the vast majority of model platforms—domestic and international—expose a more general Chat-style protocol. These are not “different versions” of the same thing; rather, they are misaligned on multiple levels:

    • Different request paths: one uses /messages, the other uses /chat/completions, and the endpoints and routing rules differ completely;
    • Different message structures: the system prompt is either a standalone top-level field or a system role entry within the message array;
    • Different parameter names: for example, max_tokens versus max_output_tokens, and stop versus stop_sequences;
    • Different tool-call formats: the request descriptions and return structures for function calling (how the tool name and parameter JSON are organized) differ systematically;
    • Different streaming responses: for SSE-based incremental output, the diff field names, event types, and end markers are all different;
    • Different authentication and usage accounting: the authentication header fields, error response formats, and how token usage is measured each vary.

    In short: these two protocols are incompatible in both request paths and parameter structures, so direct integration is bound to fail. This was the central crux of the whole ordeal.

    3. The wrong turn: blindly adopting “universal proxy” tools

    Once you realize the protocols are incompatible, the first reaction for many is to find a “universal protocol conversion” open-source proxy—one that claims “any model can be embedded into a coding tool.” For a developer who just wants to get started quickly, this sounds almost too good to be true: install it, tweak a config, and it seems like it can handle everything.

    In practice, though, these generic middleware layers tend to run into several kinds of problems:

    • They cover only the main path, not the edge features. Basic conversation works, but the moment tool calling, streaming output, or multi-turn context comes into play, conversion starts to break.
    • Their protocol assumptions are too strong. They assume vendors are largely similar, so when they meet a proprietary protocol that differs more significantly, field mapping is either missed or misaligned.
    • They are black boxes that are hard to debug. A request goes out with no response, and you cannot tell whether the coding tool sent it wrong, the proxy translated it wrong, or the upstream model failed to handle it—making diagnosis extremely costly.
    • They are fragile to maintain. When the upstream upgrades or tweaks its protocol, the conversion rules that once worked break immediately—running today, failing tomorrow.

    The real lesson is this: the essence of the problem is not “missing a forwarding tool” but “missing a rigorous protocol adaptation layer.” Pinning your hopes on a “universal = ready to use” black box is a recipe for more pitfalls.

    4. The key insight: the protocol adapter layer is the real protagonist

    Once this is clear, the path forward becomes obvious: rather than hunting for an all-purpose proxy, take control of your own protocol adapter layer. It is essentially a reverse proxy plus a protocol-translation gateway that sits between the coding tool and the upstream model, translating each side into a language the other can understand.

    A minimal viable adapter must at least handle the following:

    1. # Pseudocode: core responsibilities of the protocol adapter (illustrative, not a specific product API)
    2. def handle_request(tool_request):
    3. # 1. Request conversion: coding tool protocol -> upstream Chat protocol
    4. upstream_req = map_request(tool_request)
    5. # - Normalize the position of the system prompt
    6. # - Map parameter names: max_tokens / stop / temperature ...
    7. # - Convert tool (function) definition structures
    8. upstream_resp = call_upstream(upstream_req)
    9. # 2. Response conversion: upstream protocol -> coding tool protocol
    10. if is_streaming(tool_request):
    11. return stream_adapter(upstream_resp) # translate SSE event by event
    12. else:
    13. return map_response(upstream_resp) # convert message and usage fields
    14. def stream_adapter(upstream_stream):
    15. for event in upstream_stream:
    16. # Unify incremental fields: delta content, tool-call deltas, end markers
    17. yield translate_event(event)

    The design points can be summarized in four principles:

    1. Make field-mapping tables explicit and maintainable. Model the message structures, parameter names, and error codes as clear mappings rather than scattering them across if-else statements in the code.
    2. Handle tool calling separately. Function calling has the largest differences in both request descriptions and return structures and must be adapted on its own; otherwise the coding tool’s ability to “edit files and run commands” will break.
    3. Translate streaming event by event. It is not enough to align only the final result—you must ensure that deltas, tool-call fragments, and end signals carry consistent semantics throughout the incremental process.
    4. Align usage and errors. Token-count fields and error response formats must be normalized; otherwise the upper-layer tool’s context management and retry logic will make wrong decisions.

    5. Practical advice: a few tips to avoid pitfalls

    • Get the shortest path working first. Validate protocol mapping with the simplest single-turn conversation, then gradually add streaming and tool calling. This avoids debugging too many variables at once.
    • Treat the adapter as an independent service. Deploying it separately—with observability such as logging requests and responses—makes problems far easier to diagnose than embedding it inside a coding-tool plugin.
    • Prefer upstreams with good protocol compatibility. Compared with model interfaces whose generality varies widely, a platform like Baidu AI Cloud that offers standardized model services and tool-calling capabilities can significantly reduce the work of building the adapter; if you can pick an interface aligned with the mainstream Chat style, you avoid writing large patches for proprietary fields.
    • Leave room for upgrades. Protocols change, so the adapter’s mapping rules must be easy to adjust quickly. Plan for version compatibility and regression testing.

    6. Summary

    The biggest takeaway from this effort was not connecting a particular model, but realizing one thing: whether the combination of “a great coding tool plus a cost-effective domestic model” actually works depends not on how powerful the model is, but on whether the protocol between the two can be aligned. Do not get led astray by selling points like “universal proxy, out of the box.” What truly determines success or failure is that visible, editable, and maintainable protocol adaptation layer. Once you tackle the differences in request paths, message structures, parameter names, tool calling, and streaming responses one by one, you are just one step away from “getting it working end to end.”