SkillAgentSearch skills...

Com.openai.unity

A Non-Official OpenAI Rest Client for Unity (UPM)

Install / Use

/learn @RageAgainstThePixel/Com.openai.unity

README

OpenAI

Discord openupm openupm

Based on OpenAI-DotNet

A OpenAI package for the Unity to use though their RESTful API. Independently developed, this is not an official library and I am not affiliated with OpenAI. An OpenAI API account is required.

All copyrights, trademarks, logos, and assets are the property of their respective owners.

Installing

Requires Unity 2021.3 LTS or higher.

The recommended installation method is though the unity package manager and OpenUPM.

Via Unity Package Manager and OpenUPM

Terminal

openupm add com.openai.unity

Manual

  • Open your Unity project settings
  • Add the OpenUPM package registry:
    • Name: OpenUPM
    • URL: https://package.openupm.com
    • Scope(s):
      • com.openai
      • com.utilities

scoped-registries

  • Open the Unity Package Manager window
  • Change the Registry from Unity to My Registries
  • Add the OpenAI package

Via Unity Package Manager and Git url

[!WARNING] This repo has dependencies on other repositories! You are responsible for adding these on your own.


Documentation

Check out our new api docs!

https://rageagainstthepixel.github.io/OpenAI-DotNet

Table of Contents

Authentication

There are 4 ways to provide your API keys, in order of precedence:

[!WARNING] We recommended using the environment variables to load the API key instead of having it hard coded in your source. It is not recommended use this method in production, but only for accepting user credentials, local testing and quick start scenarios.

  1. Pass keys directly with constructor :warning:
  2. Unity Scriptable Object :warning:
  3. Load key from configuration file
  4. Use System Environment Variables

You use the OpenAIAuthentication when you initialize the API as shown:

Pass keys directly with constructor

[!WARNING] We recommended using the environment variables to load the API key instead of having it hard coded in your source. It is not recommended use this method in production, but only for accepting user credentials, local testing and quick start scenarios.

var api = new OpenAIClient("sk-apiKey");

Or create a OpenAIAuthentication object manually

var api = new OpenAIClient(new OpenAIAuthentication("sk-apiKey", "org-yourOrganizationId", "proj_yourProjectId"));

Unity Scriptable Object

You can save the key directly into a scriptable object that is located in the Assets/Resources folder.

You can create a new one by using the context menu of the project pane and creating a new OpenAIConfiguration scriptable object.

[!WARNING] Beware checking this file into source control, as other people will be able to see your API key. It is recommended to use the OpenAI-DotNet-Proxy and authenticate users with your preferred OAuth provider.

Create new OpenAIConfiguration

Load key from configuration file

Attempts to load api keys from a configuration file, by default .openai in the current directory, optionally

Related Skills

View on GitHub
GitHub Stars591
CategoryDevelopment
Updated1h ago
Forks86

Languages

C#

Security Score

100/100

Audited on Mar 30, 2026

No findings