> For the complete documentation index, see [llms.txt](https://docs.convai.com/api-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/advanced-topics/custom-providers.md).

# 凭证、身份和存储

将 SDK 的默认凭证、身份和持久化提供器替换为适合你部署环境的自定义实现。

Convai Unity SDK 提供可直接用于生产环境的默认配置，涵盖凭据、终端用户身份和会话持久化。每个系统都由一个定义明确的接口支持；当默认设置不适合你的部署时，你可以实现并注册该接口。

### 何时使用自定义提供程序

* **CI / 密钥管理** — API 密钥不得存储在 `ConvaiSettings.asset`；它来自环境变量或密钥保险库。
* **基于认证的身份** — 你的应用有自己的用户系统（OAuth、Steam、自定义 LMS），并且你希望将 Convai 的长期记忆和 MAU（每月活跃用户）跟踪与你的用户 ID 关联。
* **云存档或自定义存储** — 会话数据必须持久保存到远程服务、加密存储或非`PlayerPrefs` 存储。

这三种提供程序都通过子类化进行注册 `ConvaiManager` 并重写 `CreateRuntimeBuilder()`。这意味着你需要创建一个新的 C# 类，该类继承自 `ConvaiManager`，将其作为组件添加到同一个 GameObject 上，原来 `ConvaiManager` 所在的位置，并移除原来的组件。例外情况：身份和元数据提供程序也可以通过直接设置器在 `ConvaiManager`上进行设置，这不需要子类化，而且当你不需要更改任何其他设置时更简单。

### 下一步

{% content-ref url="/pages/fdc49f930fecd7fb00d337f46a900594f8f26fb5" %}
[自定义凭证提供器](/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/advanced-topics/custom-providers/custom-credential-provider.md)
{% endcontent-ref %}

{% content-ref url="/pages/4f9746367744635226a122f62cd5fa9abd892214" %}
[自定义身份提供器](/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/advanced-topics/custom-providers/custom-identity-provider.md)
{% endcontent-ref %}

{% content-ref url="/pages/2e48fc65c96962e4ad153649c1ead0353c2ca940" %}
[自定义持久化提供器](/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/advanced-topics/custom-providers/custom-persistence-provider.md)
{% endcontent-ref %}

{% content-ref url="/pages/39c79b51732b2441a1b8ec0d5d75288e27e81e91" %}
[个人访问令牌](/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/advanced-topics/custom-providers/personal-access-token.md)
{% endcontent-ref %}

<table data-view="cards"><thead><tr><th></th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td><strong>自定义凭据提供程序</strong><br>从环境变量、密钥保险库或任何运行时来源提供 API 凭据，而不是使用 ConvaiSettings。</td><td><a href="/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/advanced-topics/custom-providers/custom-credential-provider.md">自定义凭证提供器</a></td></tr><tr><td><strong>自定义身份提供程序</strong><br>将 Convai 的终端用户身份与你自己的认证系统绑定，以实现稳定的按用户记忆和准确的每月活跃用户（MAU）跟踪。</td><td><a href="/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/advanced-topics/custom-providers/custom-identity-provider.md">自定义身份提供器</a></td></tr><tr><td><strong>自定义持久化提供程序</strong><br>用远程服务、加密文件存储或任何键值实现替换默认会话存储。</td><td><a href="/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/advanced-topics/custom-providers/custom-persistence-provider.md">自定义持久化提供器</a></td></tr><tr><td><strong>个人访问令牌</strong><br>从你的 API 密钥生成短期令牌，这样真实密钥就不会随你的 Unity 构建一起发布。</td><td><a href="/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/advanced-topics/custom-providers/personal-access-token.md">个人访问令牌</a></td></tr></tbody></table>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/advanced-topics/custom-providers.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
