Unity 2020.3+ UPM Compatible License: MIT Sponsor Last Commit Code Size
Maintenance GitHub stars GitHub forks GitHub issues Windows WebGL Android

# 🐳 DeepSeek API for Unity > πŸ’¬ A clean, modular Unity integration for DeepSeek's powerful LLMs β€” chat, reasoning, and task automation made easy. > ⚠️ **Note**: This is an unofficial integration not affiliated with or endorsed by DeepSeek. --- ## ✨ Features - βœ… Clean, reusable SDK for DeepSeek API - πŸ”„ Supports true SSE-based streaming and non-streaming chat completions - 🧠 Compatible with multiple models (DeepSeek Chat, Reasoner) - 🎨 Modular & customizable UI chat component - πŸ” Secure API key storage (runtime-safe) - βš™οΈ Built with Unity Package Manager (UPM) - πŸ§ͺ Includes sample scene & prefabs --- ### 🧩 Supported Platforms & Unity Versions | Platform | Unity 2020.3 | Unity 2021 | Unity 2022 | Unity 6 | Notes | | --- | --- | --- | --- | --- | --- | | **Windows** | βœ… | βœ… | βœ… | βœ… | Fully supported (tested with IL2CPP & Mono) | | **Android** | βœ… | βœ… | βœ… | βœ… | Requires internet permission in manifest | | **WebGL** | ⚠️ *Partial* | ⚠️ *Partial* | βœ… | βœ… | Streaming unsupported; add CORS headers on server | | **Linux** | ❓ | ❓ | ❓ | ❓ | Likely works, but not yet tested | | **macOS** | ❓ | ❓ | ❓ | ❓ | Not tested, expected to work | | **iOS** | ❓ | ❓ | ❓ | ❓ | Not tested, expected to work (HTTPS required) | | **Consoles** | ❌ | ❌ | ❌ | ❌ | Not supported (Unity license + network limitations) | > ❓ = Not tested yet β€” expected to work but needs verification > > > ⚠️ = Partial support (some limitations) > --- ## 🧰 Requirements - Unity 2020.3 LTS or newer - TextMeshPro (via Package Manager) - DeepSeek API Key from [platform.deepseek.com](https://platform.deepseek.com/) --- ## πŸ“¦ Installation ### Option 1: Via Git URL (Unity Package Manager) 1. Open your Unity project 2. Go to **Window > Package Manager** 3. Click `+` β†’ **Add package from Git URL** 4. Paste: ```csharp https://github.com/yagizeraslan/DeepSeek-Unity.git ``` 5. βœ… Done --- ## πŸš€ Getting Started ### πŸ”§ Setup 1. After installation, download Sample scene from Package Manager 2. Paste your **API key** into the DeepSeekSettings.asset. 3. Hit Play β€” and chat with DeepSeek AI in seconds πŸ’¬ --- ## πŸ§ͺ Sample Scene To test everything: 1. In **Package Manager**, under **DeepSeek API for Unity**, click **Samples** 2. Click **Import** on `DeepSeek Chat Example` 3. Open: ```csharp Assets/Samples/DeepSeek API for Unity/1.0.1/DeepSeek Chat Example/Scenes/DeepSeek-Chat.unity ``` 4. Press Play β€” you're live. - You can change model type and streaming mode during play β€” the SDK picks up changes automatically for each new message. - You can also press **Enter** instead of clicking Send button β€” handy for fast testing. --- ## πŸ” API Key Handling - During dev: Store key via `EditorPrefs` using the DeepSeek Editor Window - In production builds: Use the `DeepSeekSettings` ScriptableObject (recommended) **DO NOT** hardcode your key in scripts or prefabs β€” Unity will reject the package. --- ## 🧱 Architecture Overview | Layer | Folder | Role | | --- | --- | --- | | API Logic | `Runtime/API/` | HTTP & model logic | | Data Models | `Runtime/Data/` | DTOs for requests/responses | | UI Component | `Runtime/UI/` | MonoBehaviour & Controller | | Config Logic | `Runtime/Common/` | Secure key storage | | Editor Tools | `Editor/` | Editor-only settings UI | | Example Scene | `Samples~/` | Demo prefab, scene, assets | --- ## 🧩 Example Integration ### πŸ• Non-Streaming (Full Response) ```csharp [SerializeField] private DeepSeekSettings config; private async void Start() { var api = new DeepSeekApi(config); var request = new ChatCompletionRequest { model = DeepSeekModel.DeepSeek_V3.ToModelString(), messages = new ChatMessage[] { new ChatMessage { role = "system", content = "You're a helpful assistant." }, new ChatMessage { role = "user", content = "Tell me something cool." } } }; var response = await api.CreateChatCompletion(request); Debug.Log("[FULL RESPONSE] " + response.choices[0].message.content); } ``` ### πŸ”„ Streaming (Real-Time Updates) ```csharp [SerializeField] private DeepSeekSettings config; private void Start() { RunStreamingExample(); } private void RunStreamingExample() { var request = new ChatCompletionRequest { model = DeepSeekModel.DeepSeek_V3.ToModelString(), messages = new ChatMessage[] { new ChatMessage { role = "user", content = "Stream a fun fact about the ocean." } }, stream = true }; var streamingApi = new DeepSeekStreamingApi(); streamingApi.CreateChatCompletionStream( request, config.apiKey, partial => { Debug.Log("[STREAMING] " + partial); // Called for each streamed segment } ); } ``` --- ## πŸ›  Advanced Usage ### πŸ”„ Streaming Support DeepSeek-Unity supports **real-time streaming** using DeepSeek's official `stream: true` Server-Sent Events (SSE) endpoint. βœ… Uses Unity's `DownloadHandlerScript` for chunked response handling βœ… UI updates per-token (no simulated typewriter effect) βœ… No coroutines, no external libraries β€” works natively in Unity To enable: - Check `Use Streaming` in the chat prefab or component - Partial responses will automatically stream into the UI πŸ“Œ You can toggle streaming on/off at runtime. ### πŸ’¬ Multiple Models ```csharp DeepSeekModel.DeepSeek_V3 DeepSeekModel.DeepSeek_R1 ``` --- ## 🐞 Troubleshooting **Can't add component?** β†’ Make sure you dragged `DeepSeekSettings.asset` into the DeepSeekChat.cs's Config field. **Streaming not working?** β†’ Make sure you're on a platform that supports `DownloadHandlerScript` (Standalone or Editor). β†’ WebGL and iOS may have platform limitations for live SSE streams. **Seeing JSON parse warnings in streaming mode?** β†’ These are normal during SSE β€” they occur when the parser receives partial chunks. They're automatically skipped and won't affect the final output. --- ## πŸ’– Support This Project If you find **DeepSeek-Unity** useful, please consider supporting its development! - [Become a sponsor on GitHub Sponsors](https://github.com/sponsors/yagizeraslan) - [Buy me a coffee on Ko-fi](https://ko-fi.com/yagizeraslan) Your support helps me continue maintaining and improving this project. Thank you! πŸš€ --- ## πŸ“„ License Unofficial integration. DeepSeekβ„’ is a trademark of Hangzhou DeepSeek Artificial Intelligence Co., Ltd. This project is licensed under the MIT License. --- ## 🀝 Contact & Support **Author**: [Yağız ERASLAN](https://www.linkedin.com/in/yagizeraslan/) πŸ“¬ yagizeraslan@gmail.com πŸ’¬ GitHub Issues welcome!