← Back to learning path

This chapter has not been reviewed in English; the original Simplified Chinese is shown.

Chapter · Published

vLLM 服务化:从本地兼容接口开始 (original language)

使用官方 OpenAI 兼容接口启动本地模型,并验证鉴权和请求边界。

Source: knowledge/p24-c/collection_62e019bd665ea4bb7c5eb169/tutorials/deployment-vllm-serving.mdModel deployment engineering
Chapter progress 0%Learning path progress 0% · 0/10 chapters completedContinue learning path →

vLLM 提供 OpenAI 兼容的服务入口,适合先在本地验证请求格式,再把运行参数纳入部署配置。示例只验证连通性,不声称任何吞吐或成本结果。

核心概念

服务启动参数会影响显存、上下文长度和并发。模型来源、served-model-name、API key、端口和健康探针都应写入版本化配置;密钥通过环境变量注入。

可运行示例

import os
import requests

base = os.environ.get('VLLM_BASE_URL', 'http://127.0.0.1:8000/v1')
key = os.environ.get('VLLM_API_KEY', 'local-only')
response = requests.get(f'{base}/models', headers={'Authorization': f'Bearer {key}'}, timeout=10)
response.raise_for_status()
models = response.json().get('data', [])
assert models, 'no served model'
print(models[0]['id'])

操作步骤

  1. 按官方文档安装 vLLM,并选择有许可的模型 revision。
  2. 使用环境变量注入 API key,启动 OpenAI 兼容服务。
  3. 先请求 /v1/models,再用最小 prompt 验证响应结构。
  4. 把模型 id、端口、超时和资源限制写入部署 manifest。

Use cases

适合本地开发、内网推理服务和需要兼容 OpenAI client 的应用。

常见问题

能把模型权重直接暴露下载吗? 不应;服务端只暴露推理接口。

vLLM 一定适合所有模型吗? 不一定,应按官方支持矩阵和模型许可证核对。

官方参考

vLLM OpenAI-compatible server;vLLM GitHub。

最后核对日期:2026-11-16。版本、接口和安全边界以链接的官方资料为准;本文不虚构性能或费用结论。

Related practical cases

Knowledge实战:本地 vLLM 兼容接口冒烟测试 (original language)Knowledge实战:模型服务金丝雀发布与回滚 (original language)Knowledge实战:模型服务金丝雀与质量预算 (original language)

Related source resources

SourcevLLM

Further reading

KnowledgeAI Agents: From Core Concepts to ProductionKnowledgeStructured Outputs and Tool Contracts for Safe AgentsKnowledgeProduction Prompt Engineering: From Instructions to Measurable Contracts
Product Hub Demo · V0.3