> 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` 当前所在的位置，并移除原始组件。例外情况：身份和元数据提供程序也可以通过直接 setter 在 `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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
