Skip to main content
LibreChat is joining ClickHouse to power the open-source Agentic Data Stack 🎉 Learn more
LibreChat

查询参数

了解如何在 LibreChat 中使用 URL 查询参数配置聊天对话。动态设置模型、endpoint 和对话设置。

LibreChat 可以直接通过 URL 配置聊天对话。在聊天路径后附加查询参数,即可在聊天加载前选择 endpoint 和模型、预填输入内容或覆盖对话设置。

聊天路径

查询参数必须遵循有效的聊天路径:

  • 新对话:/c/new?
  • 现有对话:/c/[conversation-id]?(其中 conversation-id 为现有对话的 ID)
https://your-domain.com/c/new?endpoint=ollama&model=llama3%3Alatest
https://your-domain.com/c/03debefd-6a50-438a-904d-1a806f82aad4?endpoint=openAI&model=o1-mini

基本用法

endpointmodel 参数涵盖了大多数情况。请同时设置这两个参数以获得可预测的结果:

https://your-domain.com/c/new?endpoint=azureOpenAI&model=o1-mini

Endpoint 选择

单独使用 endpoint 以在不指定模型的情况下切换 endpoint:

https://your-domain.com/c/new?endpoint=google

当仅设置 endpoint 时,LibreChat 会回退到该 endpoint 上次选择的模型(来自 localStorage)。如果没有之前的选择,它将使用该 endpoint 列表中的第一个模型。

endpoint 的值必须是以下之一:

openAI, azureOpenAI, google, anthropic, assistants, azureAssistants, bedrock, agents

对于 custom endpoint,请使用其配置的名称作为值(不区分大小写):

# endpoint=perplexity for a custom endpoint named `Perplexity`
https://your-domain.com/c/new?endpoint=perplexity&model=llama-3.1-sonar-small-128k-online

模型选择

单独使用 model 来在当前 endpoint 内切换模型:

https://your-domain.com/c/new?model=gpt-4o

当仅设置 model 时,LibreChat 仅在模型存在于当前 endpoint 时才会应用它。当前 endpoint 为默认 endpoint 或最后选定的 endpoint。

Prompt

prompt 参数会预填充聊天输入框:

https://your-domain.com/c/new?prompt=Explain quantum computing

qprompt 的可互换简写:

https://your-domain.com/c/new?q=Explain quantum computing

将其与其他参数结合使用:

https://your-domain.com/c/new?endpoint=anthropic&model=claude-3-5-sonnet-20241022&prompt=Explain quantum computing

自动提交

添加 submit=true 以自动发送提示词,无需手动确认:

https://your-domain.com/c/new?prompt=Explain quantum computing&submit=true

这对于自动化工作流(Raycast、Alfred、Automator)和外部集成非常有用。将其与其他参数结合使用,即可实现完全脚本化的启动:

https://your-domain.com/c/new?endpoint=openAI&model=gpt-4&prompt=Explain quantum computing&submit=true

URL 编码

查询值中的特殊字符必须进行 URL 编码。常见的替换如下:

字符编码
:%3A
/%2F
?%3F
#%23
&%26
=%3D
+%2B
空格%20 (或 +)

例如:

Original: `Write a function: def hello()`
Encoded: `/c/new?prompt=Write%20a%20function%3A%20def%20hello()`

JavaScript 内置的 encodeURIComponent() 会为您处理编码:

const prompt = "Write a function: def hello()";
const encodedPrompt = encodeURIComponent(prompt);
const url = `/c/new?prompt=${encodedPrompt}`;
console.log(url);

在浏览器控制台(Ctrl+Shift+I)中运行此代码以查看编码后的 URL。

Model Specs, Agents, and Assistants

Model specs

通过名称选择 model spec

https://your-domain.com/c/new?spec=meeting-notes-gpt4

这会加载 spec 中定义的每一项设置。当存在 spec 时,URL 中的其他模型参数将被忽略。

Agents

通过 ID 加载 Agent 而无需指定 endpoint:

https://your-domain.com/c/new?agent_id=your-agent-id

这会自动将 endpoint 设置为 agents

Assistants

通过 ID 加载 assistant 的方式相同:

https://your-domain.com/c/new?assistant_id=your-assistant-id

这会自动将 endpoint 设置为 assistants

支持的参数

LibreChat 设置

参数描述
maxContextTokens覆盖系统定义的上下文窗口。
resendFiles控制后续消息中的文件重新提交。
promptPrefix设置自定义指令 / 系统消息。
imageDetail图像质量:lowautohigh。仅适用于 OpenAI、类 OpenAI 自定义 endpoint 以及 Azure OpenAI(默认为 auto)。
spec通过精确名称选择一个 Model Specs。设置此项后,其他模型参数将被忽略,优先使用该 spec。如果 spec 配置了 enforce: true,则 URL 查询参数要生效可能需要此参数。
fileTokenLimit文件处理的最大 token 限制,用于控制成本和资源使用。该请求值会覆盖 YAML 中的默认值。

模型参数

支持的模型参数因 endpoint 而异。数值必须符合提供商 API 的要求。

OpenAI, Custom, Azure OpenAI:

temperature, presence_penalty, frequency_penalty, stop, top_p, max_tokens,
reasoning_effort, reasoning_summary, verbosity, useResponsesApi, web_search, disableStreaming

Google, Anthropic:

topP, topK, maxOutputTokens, thinking, thinkingBudget, thinkingLevel, web_search

Anthropic, Bedrock (Anthropic models):

promptCache 设置为 truefalse 以切换 prompt caching:

promptCache

请参阅 Anthropic prompt caching docsBedrock prompt caching docs 以获取详细信息。

Bedrock:

# Bedrock region
region=us-west-2
# Bedrock equivalent of `max_tokens`
maxTokens=200
# Bedrock reasoning effort (for supported models like ZAI, MoonshotAI)
reasoning_effort=medium

Assistants / Azure Assistants:

# Overrides existing assistant instructions for the current run
instructions=your+instructions
# Adds the current date and time to `additional_instructions` for each run
append_current_datetime=true

这些参数中的大多数与 Model Spec Preset Fields 共享;请参阅该处以获取完整参考。

示例

单个 URL 中的多个参数:

https://your-domain.com/c/new?endpoint=google&model=gemini-2.0-flash-exp&temperature=0.7&prompt=Oh hi mark

加载带有 prompt 的 Model Specs:

https://your-domain.com/c/new?spec=meeting-notes-gpt4&prompt=Here%20is%20the%20transcript...

当使用 spec 时,其他模型参数将被忽略,以优先使用 spec 的配置。

验证

在应用所有参数之前,LibreChat 会根据其 schema 对它们进行验证。无效的参数和值将被忽略;有效的设置将应用于对话。

请谨慎使用查询参数

  • 滥用或超出提供商限制可能会导致 API 错误。
  • 如果遇到错误请求(bad request error),请点击 New Chat 重置对话。
  • 如果所选的 endpoint 不支持某个参数,则该参数无效。

最佳实践

  1. 尽可能同时设置 endpointmodel
  2. 确认 endpoint 支持您传递的每个参数。
  3. 请将数值保持在提供商的限制范围内。
  4. 在共享 URL 之前,请先测试参数组合。

查询参数可以轻松共享特定的对话配置、收藏不同的聊天设置,并从外部工具自动化启动聊天。

这篇指南怎么样?