How to Choose a Domestic LLM: Unified API Access and Multi-Model Comparison

    Selecting among Chinese LLMs is increasingly difficult because models differ in reasoning, coding, Chinese comprehension, latency, and cost. This article breaks the problem into two engineering tasks: unifying model access behind a single abstraction layer and building a reproducible evaluation process. It covers five selection dimensions, adapter design, credential management, parallel benchmarking, a scoring framework, and production reliability practices such as retry, fallback, and cost monitoring.

    1. Why LLM Selection Is Getting Harder

    The number of LLMs developed in China is growing rapidly. Models differ in reasoning ability, code generation, Chinese language understanding, long-context handling, response speed, and pricing. A model that excels at one task type may be unstable on another. Teams that commit to a single model typically face two problems: suboptimal results in certain scenarios, and high migration cost later.

    Selection can therefore be broken down into two engineering problems. First, how to call multiple models through a consistent interface so switching is cheap. Second, how to make comparison results quantitative and reproducible instead of relying on subjective impressions. The rest of this article addresses these two problems.

    2. Five Core Selection Dimensions

    Define evaluation dimensions before comparing, otherwise the process degenerates into “which answer looks nicer.” Five common dimensions:

    1. Task quality. Accuracy, information completeness, and instruction-following on your target tasks. Quality should be measured against real business samples, not generic leaderboard scores. Leaderboards reflect specific test sets whose distribution may not match your business data.

    2. Response performance. Primarily time to first token (TTFT) and total generation time. Both are affected by service load, output length, and network path, so a single measurement is meaningless. Sample repeatedly and record distribution statistics such as P50 and P95.

    3. Stability. Request timeout rate, error code distribution, and rate-limit trigger frequency. Under high concurrency or peak hours, stability often affects user experience more than peak quality. Run load tests under near-production traffic before going live.

    4. Cost. Most services bill by input and output tokens, so total cost depends on unit price and average token consumption per task. A cheaper model that requires more rounds to reach a usable result may cost more overall. Evaluate cost as “average expense per completed task.”

    5. Compliance and data boundaries. Confirm whether data crosses borders, how long request logs are retained, whether your data can be used for model training, and whether industry regulations are met. This is a veto criterion — filter on it before comparing quality.

    3. Designing a Unified Access Layer

    With multiple models in play, business code should target a single abstraction. The common approach is an adapter layer between the application and model services. Upper layers send requests in a unified message structure; the adapter maps them to each service’s endpoint, authentication scheme, and model identifier.

    This design delivers three direct benefits:

    • Switching models only requires a configuration change; business logic stays untouched;
    • The same batch of inputs can be sent to multiple models in parallel for side-by-side comparison;
    • Cross-cutting capabilities like timeouts, retries, rate limiting, and logging are implemented once instead of at every call site.

    The layer also has costs. A failure in the aggregation entry point or adapter widens the blast radius. Backends may differ in parameter defaults and valid ranges, so the adapter must validate parameters explicitly rather than relying on defaults. And each time a new service is onboarded, re-verify its terms of service, data handling practices, and availability commitments.

    4. Onboarding Workflow and Configuration Rules

    Onboarding a model service usually involves three steps.

    Step 1: Obtain credentials. Create access keys following the provider’s process. Set a key lifetime that supports periodic rotation; avoid keys that never expire. Apply least privilege — grant only the permissions the current use case needs.

    Step 2: Manage credentials. Keys must never be written into source code or version control. Inject them at runtime via environment variables or a secrets management service. Keep only the last few characters of a key in logs for troubleshooting; full keys must never appear in any output.

    Step 3: Configure the client. The client needs three parameters: service endpoint, access key, and model identifier. Always copy the model identifier from the provider’s documentation — different versions of the same model may have different identifiers.

    The following pseudocode illustrates the configuration structure. Field names and endpoint paths should follow the API documentation of the service you use.

    1. # Example code: configuration read from environment variables to avoid hardcoding secrets
    2. API_BASE = read_env("LLM_API_BASE")
    3. API_KEY = read_env("LLM_API_KEY")
    4. def chat(model_id, user_text, timeout_seconds=60):
    5. url = API_BASE + "<chat endpoint path, per service docs>"
    6. payload = {
    7. "model": model_id,
    8. "messages": [{"role": "user", "content": user_text}],
    9. "temperature": 0.2,
    10. }
    11. headers = {
    12. "Authorization": "Bearer " + API_KEY,
    13. "Content-Type": "application/json",
    14. }
    15. resp = send_post(url, payload, headers, timeout_seconds)
    16. validate_http_status(resp)
    17. return resp["choices"][0]["message"]["content"]

    Two points to note. First, a low temperature reduces output variance across repeated runs of the same input, which makes comparisons fairer. Second, the timeout must be set explicitly — otherwise a single slow request can hold a connection for a long time.

    5. Implementing Parallel Comparison

    The most direct way to compare models is to send the same input set to all candidates in parallel and aggregate results into one table. Parallel execution shortens total evaluation time significantly, but concurrency must be capped to avoid triggering provider rate limits.

    Illustrative logic:

    1. # Example code: call multiple models in parallel on the same input
    2. def compare_models(model_ids, prompt, max_workers=4):
    3. results = parallel_map(
    4. lambda m: {"model": m, "output": chat(m, prompt)},
    5. model_ids,
    6. max_workers=max_workers,
    7. )
    8. return results

    Building the evaluation set matters more than the calling code. Recommended steps:

    1. Extract 50–200 samples from real business logs, covering high-frequency questions and typical hard cases.
    2. Write expected key points for each sample rather than a single canonical answer — open-ended tasks usually have multiple valid expressions.
    3. Categorize samples (e.g., Q&A, reasoning, code, summarization, rewriting) so results can be reviewed per category.
    4. Run each model on each sample at least three times, recording output and latency.

    Scoring should combine rule-based checks with human review. Format-related metrics can be checked programmatically — for example, whether structured output parses correctly. Content-related metrics require reviewers scoring against a rubric. A reference rubric:

    Dimension Method Criteria
    Factual correctness Manual check against expected key points Score per key point hit; deduct for factual errors
    Instruction following Rule-based validation Output format, length, and fields meet requirements
    Reasoning completeness Human review Steps are complete; conclusions are supported
    Time to first token Programmatic timing Record P50 and P95
    Error rate Programmatic statistics Timeouts and error codes as a share of total requests
    Cost per task Computed from token usage Average expense per task

    6. A Decision Framework

    Different businesses weight dimensions differently. Define business priorities first, then assign weights.

    • Customer service Q&A: stability and latency first, then factual correctness.
    • Coding assistance: code runnability and context understanding first.
    • Long-document summarization: long-context comprehension and per-task cost first.
    • Content generation: fluency and style controllability first.
    • Internal knowledge base: compliance boundaries and data isolation first; compare quality only after compliance passes.

    Weights can be quantified as a weighted score:

    1. # Example formula: S = w1*s1 + w2*s2 + ... + wn*sn, where w1+w2+...+wn = 1
    2. # s_i is the normalized score for dimension i; w_i is the business-defined weight

    The decision process has four recommended steps. First, filter candidates with the compliance dimension. Second, compute weighted scores on the evaluation set. Third, run canary tests with the top two models and observe behavior under real traffic. Fourth, keep the evaluation scripts under version control and re-run them when model versions update or business requirements change. Models iterate quickly — a selection conclusion is typically valid for only a few months.

    7. Production Considerations

    After a multi-model setup goes live, the following areas directly affect reliability.

    Timeouts and retries. Use exponential backoff with a maximum retry count for network errors and rate-limit errors. Unbounded retries amplify traffic and can worsen an outage when the server is under stress.

    Fallback and switching. Configure a backup model for each business scenario. When the primary model fails consecutively or latency exceeds a threshold, switch automatically to the backup and log the event for later analysis.

    Output validation. If the business depends on structured output, parse and validate fields in code. On validation failure, retry once; if it still fails, take the fallback path so bad data never reaches downstream systems.

    Logging and masking. When logging requests and responses, strip personal information such as phone numbers, ID numbers, and addresses. Log retention should follow your data management policy.

    Cost monitoring. Track call counts and token consumption per model and per business line, with usage alert thresholds. Cost anomalies usually indicate a call loop or prompt bloat — investigate promptly.

    Version recording. Every call should record the model identifier, parameter configuration, and call time. This information is the foundation for reproducing evaluation results and diagnosing quality fluctuations.