查询参数
了解如何在 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基本用法
endpoint 和 model 参数涵盖了大多数情况。请同时设置这两个参数以获得可预测的结果:
https://your-domain.com/c/new?endpoint=azureOpenAI&model=o1-miniEndpoint 选择
单独使用 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 computingq 是 prompt 的可互换简写:
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=trueURL 编码
查询值中的特殊字符必须进行 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 | 图像质量:low、auto 或 high。仅适用于 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, disableStreamingGoogle, Anthropic:
topP, topK, maxOutputTokens, thinking, thinkingBudget, thinkingLevel, web_search, url_context对于 Google endpoint,设置 url_context=true 以允许受支持的 Gemini 文本模型读取用户消息中包含的 URL。当启用 URL Context 时,YouTube URL 将通过原生视频理解功能进行处理。
Anthropic, Bedrock (Anthropic models), OpenRouter 自定义 endpoint:
将 promptCache 设置为 true 或 false 以切换 prompt caching。将 promptCacheTtl 设置为 5m 或 1h 以在启用 prompt caching 时选择缓存生存时间:
promptCache
promptCacheTtl=1h请参阅 Anthropic prompt caching docs 和 Bedrock 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=mediumAssistants / 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) 错误,请点击 New Chat 重置对话。
- 如果所选的 endpoint 不支持某个参数,则该参数无效。
最佳实践
- 尽可能同时设置
endpoint和model。 - 确认 endpoint 支持您传递的每个参数。
- 请将数值保持在提供商的限制范围内。
- 在分享 URL 之前,请先测试参数组合。
查询参数可以轻松共享特定的对话配置、收藏不同的聊天设置,并从外部工具自动化启动聊天。
这篇指南怎么样?