← all repositories
srcnalt/OpenAI-Unity

Your OpenAI API Key Doesn’t Belong in a Game Build

An unofficial C# wrapper that exposes OpenAI’s chat and image APIs directly inside Unity scripts.

OpenAI-Unity
Not currently ranked — collecting fresh signals.
star history

What it does

This is a C# wrapper around the OpenAI API packaged for Unity’s Package Manager. It exposes endpoints like CreateChatCompletion and CreateChatCompletionAsync through an OpenAIApi class, and ships with sample scenes demonstrating ChatGPT-style chat and DALL-E image generation. Your game scripts can send prompts and receive answers without leaving the engine.

The interesting bit

The README spends as much energy warning you about API key security as it does explaining features, which is either refreshing honesty or a tell: it admits that shipping an OpenAI key inside a Unity build is a bad idea, then suggests storing it in a local auth.json file anyway. That tension—client-side convenience versus server-side security—hovers over every sample scene.

Key highlights

  • Async and streaming chat completions via CreateChatCompletionAsync, with partial responses delivered through callbacks
  • Packaged for Unity Package Manager and ships with two sample scenes: a ChatGPT-style chat and a DALL-E image generator
  • Build support matrix covers Windows, Android, iOS, Oculus 2, and WebGL across Unity 2019.4 through 2022.3
  • Unusually frank documentation: the README explicitly warns that production use should stay server-side to avoid leaking API keys

Caveats

  • WebGL builds hit two documented snags: OpenAI’s CORS policy blocks generated image downloads locally, and Unity 2020’s WebGL player returns empty stream responses
  • Linux and macOS targets are listed as untested across every supported Unity version

Verdict

Grab this if you are prototyping AI features in Unity and want ready-made async API calls from C# scripts. Leave it alone if you are shipping a production title and took the README’s own security advice seriously—because it explicitly warns against exposing API keys in any client-side code.

Frequently asked

What is srcnalt/OpenAI-Unity?
An unofficial C# wrapper that exposes OpenAI’s chat and image APIs directly inside Unity scripts.
Is OpenAI-Unity open source?
Yes — srcnalt/OpenAI-Unity is open source, released under the MIT license.
What language is OpenAI-Unity written in?
srcnalt/OpenAI-Unity is primarily written in C#.
How popular is OpenAI-Unity?
srcnalt/OpenAI-Unity has 843 stars on GitHub.
Where can I find OpenAI-Unity?
srcnalt/OpenAI-Unity is on GitHub at https://github.com/srcnalt/OpenAI-Unity.

heatdrop uses Google Analytics to see which pages get read — nothing else. Your call. How we handle data.