> ## Documentation Index
> Fetch the complete documentation index at: https://docs.muna.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Using the OpenAI Client

> Run models locally with an OpenAI-style client.

The SDK exposes an OpenAI-style client at `muna.beta.openai`, with the same interface as the
official OpenAI client.

<Tip>
  You can easily compile your own custom models to be compatible with Muna's OpenAI client.
  [See the guide](/compile/openai).
</Tip>

## Creating Chat Completions

Muna supports running large language models via our client's
`openai.chat.completions.create` API:

<CodeGroup>
  ```js JavaScript icon="js" theme={null}
  import { Muna } from "muna"

  // 💥 Create a Muna client
  const openai = new Muna().beta.openai;

  // 🔥 Create a chat completion
  const completion = await openai.chat.completions.create({
    model: "@google/gemma-3-270m",
    messages: [{ role: "user", content: "What is life?" }]
  });

  // 🚀 Print the result
  console.log(completion.choices[0]);
  ```

  ```py Python icon="python" theme={null}
  from muna import Muna

  # 💥 Create a Muna client
  openai = Muna().beta.openai

  # 🔥 Create a chat completion
  completion = openai.chat.completions.create(
    model="@google/gemma-3-270m",
    messages=[{ "role": "user", "content": "What is life?" }]
  )

  # 🚀 Print the result
  print(completion.choices[0].message)
  ```

  ```cs Unity icon="unity" theme={null}
  using Muna;
  using Muna.Beta.OpenAI;
  using static Muna.Beta.OpenAI.ChatMessage;

  // 💥 Create a Muna client
  var openai = MunaUnity.Create().Beta.OpenAI;

  // 🔥 Create a chat completion
  var completion = await openai.Chat.Completions.Create(
    model: "@google/gemma-3-270m",
    messages: new[] {
      new ChatMessage { Role = "user", Content = "What is life?" }
    }
  );

  // 🚀 Print the result
  Debug.Log(completion.Choices[0].Message);
  ```
</CodeGroup>

## Streaming Completions

Our OpenAI client also supports creating streaming completions:

<CodeGroup>
  ```js JavaScript icon="js" theme={null}
  import { Muna } from "muna"

  // 💥 Create a Muna client
  const openai = new Muna().beta.openai;

  // 🔥 Stream a chat completion
  const stream = await openai.chat.completions.create({
    model: "@google/gemma-3-270m",
    messages: [{ role: "user", content: "What is life?" }],
    stream: true
  });

  // 🚀 Use completion chunks
  for await (const chunk of stream)
    ...
  ```

  ```py Python icon="python" theme={null}
  from muna import Muna

  # 💥 Create a Muna client
  openai = Muna().beta.openai

  # 🔥 Stream a chat completion
  stream = openai.chat.completions.create(
    model="@google/gemma-3-270m",
    messages=[{ "role": "user", "content": "What is life?" }],
    stream=True
  )

  # 🚀 Use completion chunks
  for chunk in stream:
    ...
  ```

  ```cs Unity icon="unity" theme={null}
  using Muna;
  using Muna.Beta.OpenAI;
  using static Muna.Beta.OpenAI.ChatMessage;

  // 💥 Create a Muna client
  var openai = MunaUnity.Create().Beta.OpenAI;

  // 🔥 Stream a chat completion
  var stream = openai.Chat.Completions.Stream(
    model: "@google/gemma-3-270m",
    messages: new[] {
      new ChatMessage { Role = "user", Content = "What is life?" }
    },
  );

  // 🚀 Use completion chunks
  await foreach (var chunk in stream)
    ...
  ```
</CodeGroup>

## Creating Embeddings

Muna supports running text embedding models via our client's
`openai.embeddings.create` API:

<CodeGroup>
  ```js JavaScript icon="js" theme={null}
  import { Muna } from "muna"

  // 💥 Create a Muna client
  const openai = new Muna().beta.openai;

  // 🔥 Create a text embedding
  const embedding = await openai.embeddings.create({
      model: "@nomic/nomic-embed-text-v1.5",
      input: "What is the capital of France?"
  });

  // 🚀 Use the embedding
  console.log(embedding.data[0].embedding);
  ```

  ```py Python icon="python" theme={null}
  from muna import Muna

  # 💥 Create a Muna client
  openai = Muna().beta.openai

  # 🔥 Create a text embedding
  embedding = openai.embeddings.create(
      model="@nomic/nomic-embed-text-v1.5",
      input="What is the capital of France?"
  )

  # 🚀 Use the embedding
  print(embedding.data[0].embedding)
  ```

  ```csharp Unity icon="unity" theme={null}
  using Muna;

  // 💥 Create a Muna client
  var openai = MunaUnity.Create().Beta.OpenAI;

  // 🔥 Create a text embedding
  var embedding = await openai.Embeddings.Create(
      model: "@nomic/nomic-embed-text-v1.5",
      input: "What is the capital of France?"
  );

  // 🚀 Use the embedding
  Debug.Log(embedding.data[0].Floats);
  ```
</CodeGroup>

## Creating Speech

Muna supports running text-to-speech models via our client's
`openai.audio.speech.create` API:

<CodeGroup>
  ```js JavaScript icon="js" theme={null}
  import { Muna } from "muna"

  // 💥 Create a Muna client
  const openai = new Muna().beta.openai;

  // 🔥 Create speech
  const response = await openai.audio.speech.create({
      model: "@hexgrad/kokoro-tts",
      input: "What a time to be alive",
      voice: "af_jessica"
  });

  // 🚀 Use the speech
  console.log(response);
  ```

  ```py Python icon="python" theme={null}
  from muna import Muna

  # 💥 Create a Muna client
  openai = Muna().beta.openai

  # 🔥 Create speech
  response = openai.audio.speech.create(
      model="@hexgrad/kokoro-tts",
      input="What a time to be alive",
      voice="af_jessica"
  )

  # 🚀 Use the speech
  print(response)
  ```
</CodeGroup>

## Creating Transcriptions

Muna supports using speech-to-text models via our client's `openai.audio.transcriptions.create` API:

<CodeGroup>
  ```js JavaScript icon="js" theme={null}
  import { Muna } from "muna"

  // 💥 Create a Muna client
  const openai = new Muna().beta.openai;

  // 🔥 Create transcription
  const transcription = await openai.audio.transcriptions.create({
    model: "@moonshine/moonshine-base",
    file: audioFile
  });

  // 🚀 Use the transcribed text
  console.log(transcription.text);
  ```

  ```py Python icon="python" theme={null}
  from muna import Muna

  # 💥 Create a Muna client
  openai = Muna().beta.openai

  # 🔥 Create transcription
  transcription = openai.audio.transcriptions.create(
    model="@moonshine/moonshine-base",
    file=audio_file
  )

  # 🚀 Use the transcribed text
  print(transcription.text)
  ```
</CodeGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.