A Practical Guide to Model Selection and Unified Inference for Domestic LLMs

    This guide provides a practical framework for selecting domestic (China-developed) large language models and integrating them through a unified inference gateway. It covers a six-dimensional evaluation framework covering task fit, context handling, cost, stability, compliance, and operational complexity, along with scenario-specific selection strategies, a reference gateway architecture, step-by-step integration advice, and ongoing governance practices such as regression testing and canary releases. The goal is to help development teams make model choices based on measurable business requirements rather than leaderboard rankings, while avoiding vendor lock-in and maintaining architecture stability.

    Define the Problem First: Selection Is About Constrained Optimization, Not Leaderboard Rankings

    When faced with the growing number of domestic large language models, developers often fall into two common traps: relying solely on benchmark leaderboards, or judging a model by a single conversational test. Leaderboards reflect general capabilities to some degree, but they cannot answer the questions that matter most in production: What are your actual business tasks? What is your call volume? What are your latency requirements? Do you need structured output, tool calling, long context, or multimodal input? Can your data leave your infrastructure? What is your budget? Is output quality stable across model version updates?

    Model selection should therefore be treated as a multi-objective decision problem—finding the right balance across capability, cost, latency, stability, compliance, and operational complexity. A recommended approach is to build a shortlist of candidate models, score them with a business-specific evaluation set, and then route through a unified inference service. This prevents the business logic from being tightly coupled to any single model, allowing for rapid experimentation and stable architecture even when models are upgraded or replaced.

    A Six-Dimension Evaluation Framework

    1. Task Fit

    Do not use generic conversational quality as a proxy for business effectiveness. Build an evaluation set around real tasks: customer service Q&A, contract summarization, code generation, log analysis, report interpretation, knowledge-base retrieval, and similar. Each task type should include at least dozens to hundreds of samples covering typical inputs, edge cases, and adversarial inputs. Scoring dimensions should include correctness, completeness, instruction following, format compliance, citation grounding, and safety. For JSON output scenarios, track parse failure rates separately; for tool-calling scenarios, measure parameter accuracy and multi-step completion rates.

    2. Context and Output Capabilities

    Long context does not automatically mean effective long context. When evaluating, test needle-in-a-haystack retrieval, cross-paragraph summarization, long-document summarization, and long-conversation memory. On the output side, pay attention to maximum output length, streaming stability, structured output reliability, and truncation behavior. If multimodal input is needed, validate performance on images, tables, and scanned documents—do not infer multimodal ability from text-only benchmarks.

    3. Cost and Performance

    Cost is not just about per-token pricing. Factor in the number of tokens required to complete a task, retry rates, and downstream human review costs. On the performance side, track time-to-first-token, P95 end-to-end latency, concurrent throughput, and rate-limit thresholds. For interactive scenarios, time-to-first-token is critical to user experience; for batch processing, throughput and per-task cost are more relevant. Run stress tests with identical business requests and record success rates, latency distributions, and failure reasons.

    4. Stability and Version Management

    Model services can change behavior due to version updates, resource constraints, or regional differences. Confirm whether the model identifier is stable, whether a fixed version can be pinned, and whether there is a change-notification mechanism. Maintain a regression evaluation set for the production environment, and run core test cases every time a model or version is switched, to avoid silent upgrades causing prompt failures or output format drift.

    5. Security, Compliance, and Data Governance

    Clarify whether your data will be used for training, log retention policies, encryption in transit and at rest, access auditing, and permission isolation. When handling personal information, trade secrets, or regulated data, prefer solutions that support data masking, private network access, and audit logging. If your team already runs on Baidu AI Cloud, general model services from that platform may be reasonable candidates, but always validate against your own business evaluation set and compliance requirements.

    6. Ecosystem and Operational Complexity

    Can the candidate model be integrated through a unified interface? Does it support streaming, function calling, structured output, and batch inference? Are observability metrics and error-code documentation available? On the operational side, pay attention to key rotation, rate-limit retries, circuit breaking, cost alerts, and trace tracking across calls. The richer the ecosystem, the more important a model gateway becomes to avoid each business team duplicating integration work.

    Scenario-Based Selection Strategy

    Online Customer Service and Knowledge-Base Q&A: Prioritize factual accuracy, grounded citation, and low latency. A layered routing approach is recommended—retrieval-augmented generation (RAG) combined with a smaller model for common questions and a larger model for complex escalations. Frequent questions can be served through caching or small models; complex ones can be escalated to a stronger model.

    Code Generation and Developer Assistance: Focus on code correctness, context comprehension, patch applicability, and security vulnerability propensity. Evaluate using real repository snippets, measuring compile pass rates, unit test pass rates, and human adoption rates. Code tasks should not be judged by natural language metrics alone.

    Document Processing and Data Analysis: Long-document summarization, table understanding, and structured extraction are core requirements. Test information omission in long contexts, arithmetic accuracy, and JSON field completeness. For high-risk outputs, add rule-based validation and human review.

    AI Agents and Tool Calling: Focus on multi-step planning, argument generation, error recovery, and observability. Record input/output, latency, and failure reasons for every tool call, and set maximum step counts and timeouts to prevent infinite loops and runaway costs.

    Using a Unified Inference Service for Model Abstraction

    Production systems should not hardcode business logic against a canonical model invocation. Add a “model gateway” layer to centrally handle authentication, routing, rate limiting, retries, fallbacks, caching, auditing, and cost accounting. The business side only cares about task type and priority; the gateway decides which model to invoke.

    Example configuration:

    1. model_gateway:
    2. endpoint: <unified-inference-endpoint>
    3. auth:
    4. type: bearer
    5. key_env: MODEL_API_KEY
    6. candidates:
    7. - id: <model-id-A>
    8. capabilities: [chat, json_mode, tool_call]
    9. max_context: <context-limit>
    10. cost_level: medium
    11. - id: <model-id-B>
    12. capabilities: [chat, long_context]
    13. max_context: <context-limit>
    14. cost_level: high
    15. routing:
    16. default: <model-id-A>
    17. by_task:
    18. code: <model-id-B>
    19. long_document: <model-id-B>
    20. fallback: [<model-id-A>]
    21. limits:
    22. timeout_ms: 30000
    23. max_retries: 2
    24. rate_limit_per_minute: 600

    The business call can be expressed in pseudocode:

    1. def invoke_model(task_type, messages, request_id):
    2. model_id = router.select(task_type)
    3. request = {
    4. "endpoint": "<unified-inference-endpoint>",
    5. "auth": "Bearer <API_KEY>",
    6. "model": model_id,
    7. "messages": messages,
    8. "stream": True,
    9. "request_id": request_id
    10. }
    11. return gateway.invoke(
    12. request,
    13. timeout_ms=30000,
    14. retry=2,
    15. fallback=[router.fallback_for(task_type)]
    16. )

    The gateway layer should record model ID, task type, token usage, latency, error code, and retry count. This enables cost allocation and fast traffic shifting in the event of model anomalies.

    Integration Steps and Pitfall Checklist

    The typical integration workflow includes: registering and verifying the account, creating access keys, configuring server-side environment variables, filling in the unified service endpoint, setting model IDs, running connectivity tests, wiring up streaming output, and configuring timeout/retry/fallback policies. Do not embed keys in frontend code or in the code repository—use environment variables or a key management service and rotate keys regularly. Do not hardcode model IDs across multiple business modules; centralize them in configuration.

    Common pitfalls include: only testing single-turn conversation without long-context scenarios; ignoring structured output parse failures; failing to set timeouts and causing thread accumulation; failing to distinguish rate-limit errors from model errors; committing temporary keys to the repository; lacking a regression set, leading to drift after model upgrades; and having no cost alerts, leading to runaway batch costs. Before going live, complete checks across the five dimensions: functionality, performance, security, cost, and observability.

    Evaluation, Canary Releases, and Continuous Governance

    Model selection is not a one-time task. Establish an offline evaluation set and an online canary release mechanism: offline, use a scorecard to filter candidate models; online, roll out by traffic ratio and observe success rates, latency, human adoption rates, and complaint rates. Keep a fixed evaluation sample for each version and run regression tests before any model switch. For high-risk tasks, keep human review and rule-based checks in place; for low-risk tasks in production, gradually increase automation.

    Ultimately, model selection should return to business objectives: replace subjective impressions with quantifiable evaluation, reduce binding risk through unified inference integration, and ensure that cost, security, and experience remain sustainable through governance mechanisms. This is how you maintain decision stability in a fast-evolving model ecosystem.