跳至主要內容

Tensormesh

總覽

屬性詳細資訊
說明Tensormesh 提供具備 OpenAI 相容 API 的無伺服器 AI 推論。
LiteLLM 提供者路由tensormesh/
提供者文件連結Tensormesh 文件
Default Base URLhttps://serverless.tensormesh.ai/v1
支援的操作/chat/completions/completions/responses/messages,透過 LiteLLM 的 Anthropic Messages 適配器

API 金鑰

Environment Variables
import os

os.environ["TENSORMESH_INFERENCE_API_KEY"] = "your-api-key"

模型

列出無伺服器型錄中的可用模型:

List Tensormesh Models
curl https://serverless.tensormesh.ai/v1/models

使用型錄 id 與 tensormesh/ 路由,例如 tensormesh/openai/gpt-oss-120btensormesh/MiniMaxAI/MiniMax-M2.5tensormesh/deepseek-ai/DeepSeek-V4-Flash

用法 - LiteLLM Python SDK

聊天補全

Tensormesh Chat Completion
import os
from litellm import completion

os.environ["TENSORMESH_INFERENCE_API_KEY"] = "your-api-key"

response = completion(
model="tensormesh/<your-model-name>",
messages=[{"role": "user", "content": "Say hello in one sentence."}],
)

print(response.choices[0].message.content)

串流

Tensormesh Streaming Chat Completion
import os
from litellm import completion

os.environ["TENSORMESH_INFERENCE_API_KEY"] = "your-api-key"

response = completion(
model="tensormesh/<your-model-name>",
messages=[{"role": "user", "content": "Write a short poem about inference."}],
stream=True,
)

for chunk in response:
print(chunk)

工具呼叫

Tensormesh Tool Calling
import os
from litellm import completion

os.environ["TENSORMESH_INFERENCE_API_KEY"] = "your-api-key"

tools = [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather for a city",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string", "description": "City name"}},
"required": ["city"],
},
},
}
]

response = completion(
model="tensormesh/<your-model-name>",
messages=[{"role": "user", "content": "What is the weather in San Francisco?"}],
tools=tools,
tool_choice="auto",
)

print(response.choices[0].message.tool_calls)

每個工具函式都必須包含非空的 description;Tensormesh 會拒絕沒有它的工具定義。

推理

Tensormesh 推理模型(例如 DeepSeek-V4-Flash、Qwen3.5-397B、Qwen3.6-27B、GLM-5.1、MiniMax-M2.5、Kimi-K2.6,以及 gpt-oss 模型)透過 vLLM chat-template 控制項提供 thinking 模式。將 thinking 切換(thinkingenable_thinking)與 reasoning_effort 配對,並透過 extra_body 傳遞。模型會以 reasoning_content 回傳其思路鏈。

Tensormesh Reasoning
import os
from litellm import completion

os.environ["TENSORMESH_INFERENCE_API_KEY"] = "your-api-key"

response = completion(
model="tensormesh/deepseek-ai/DeepSeek-V4-Flash",
messages=[{"role": "user", "content": "If a train travels 60 miles in 1.5 hours, what is its average speed?"}],
extra_body={"chat_template_kwargs": {"thinking": True, "reasoning_effort": "high"}},
)

print(response.choices[0].message.reasoning_content)
print(response.choices[0].message.content)

文字補全

Tensormesh Text Completion
import os
from litellm import text_completion

os.environ["TENSORMESH_INFERENCE_API_KEY"] = "your-api-key"

response = text_completion(
model="tensormesh/<your-model-name>",
prompt="Complete this sentence: Fast inference matters because",
max_tokens=32,
)

print(response.choices[0].text)

回應 API

Tensormesh Responses API
import os
import litellm

os.environ["TENSORMESH_INFERENCE_API_KEY"] = "your-api-key"

response = litellm.responses(
model="tensormesh/<your-model-name>",
input="Say hello in one sentence.",
)

print(response)

用法 - LiteLLM Proxy

將 Tensormesh 加入您的 LiteLLM Proxy 設定:

config.yaml
model_list:
- model_name: tensormesh-chat
litellm_params:
model: tensormesh/<your-model-name>
api_key: os.environ/TENSORMESH_INFERENCE_API_KEY

general_settings:
master_key: os.environ/LITELLM_MASTER_KEY

啟動 proxy:

Start LiteLLM Proxy
export TENSORMESH_INFERENCE_API_KEY="your-api-key"
export LITELLM_MASTER_KEY="sk-local-tensormesh"
litellm --config config.yaml --port 4000

# RUNNING on http://0.0.0.0:4000

對 LiteLLM Proxy 的請求必須使用 Authorization: Bearer $LITELLM_MASTER_KEY 中的 proxy key。TENSORMESH_INFERENCE_API_KEY 只會在 LiteLLM 呼叫 Tensormesh upstream 時使用。

若要進行基本啟動檢查,請使用 /health/liveliness/health/readiness/health endpoint 已通過驗證,並可能執行模型檢查。

Tensormesh via Proxy - OpenAI SDK
from openai import OpenAI

client = OpenAI(
base_url="http://localhost:4000",
api_key="sk-local-tensormesh",
)

response = client.chat.completions.create(
model="tensormesh-chat",
messages=[{"role": "user", "content": "hello from litellm"}],
)

print(response.choices[0].message.content)

Anthropic Messages 相容性

LiteLLM 可將 Anthropic Messages 格式的請求轉譯為 Tensormesh chat completions。在 Python SDK 中,請使用 Anthropic Messages facade:

Anthropic Messages through LiteLLM SDK
import os
import litellm

os.environ["TENSORMESH_INFERENCE_API_KEY"] = "your-api-key"

response = litellm.anthropic.messages.create(
model="tensormesh/<your-model-name>",
max_tokens=128,
messages=[{"role": "user", "content": "Say hello in one sentence."}],
)

print(response["content"][0]["text"])

對於 HTTP 用戶端,LiteLLM Proxy 會公開 Anthropic 相容的 /v1/messages endpoint,並將 upstream 請求路由至 Tensormesh chat completions。請在請求主體中的 model 設為 proxy model_name

Anthropic Messages through LiteLLM Proxy
curl http://localhost:4000/v1/messages \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $LITELLM_MASTER_KEY" \
-H "anthropic-version: 2023-06-01" \
-d '{
"model": "tensormesh-chat",
"max_tokens": 128,
"messages": [{"role": "user", "content": "Say hello in one sentence."}]
}'

SDK facade 與 Proxy /v1/messages endpoint 都使用 LiteLLM 的 Anthropic Messages 適配器。Tensormesh 在 upstream 接收 OpenAI 相容的 chat completion 請求。

成本追蹤

Tensormesh 無伺服器模型已註冊於 LiteLLM 的模型成本對照表,因此 LiteLLM 會自動計算每次請求的支出。在 proxy 上,成本會回傳於 x-litellm-response-cost 回應標頭中,並記錄於支出記錄。快取的輸入 token 以零計費。

常見參數

以下是建議先使用的常見參數。其他參數取決於模型,應針對目標 Tensormesh 模型進行驗證。

EndpointCommon parameters
/chat/completionsmessagesmax_tokensmax_completion_tokenstemperaturetop_pstreamstoptoolstool_choiceresponse_formatextra_bodyextra_headers
/completionspromptmax_tokenstemperaturetop_pstreamstop
/responsesinputmax_output_tokenstemperaturetop_pstreamtoolstool_choicetextextra_headers
/messagesmessagesmax_tokenstemperaturetop_pstreamtoolstool_choiceextra_headers

對於 chat completions,LiteLLM 接受 max_completion_tokens,並將其對應到 Tensormesh 的 max_tokens

附註

  • 直接 LiteLLM SDK 呼叫請使用 model="tensormesh/<your-model-name>"
  • 預設的無伺服器 base URL 為 https://serverless.tensormesh.ai/v1
  • 推理控制項(thinking/enable_thinkingreasoning_effort)會透過 extra_body.chat_template_kwargs 傳遞,並在具備推理能力的模型上會被支援。