> For the complete documentation index, see [llms.txt](https://docs.wisej.com/ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.wisej.com/ai/components/api/smartendpoint/wisej.ai.endpoints.openaiendpoint.md).

# OpenAIEndpoint

Namespace: **Wisej.AI.Endpoints**

Assembly: **Wisej.AI** (3.5.0.0)

* [SmartEndpoint](/ai/components/api/smartendpoint.md)
  * [SmartHttpEndpoint](/ai/components/api/smartendpoint/wisej.ai.endpoints.smarthttpendpoint.md)
    * [OpenAIEndpoint](/ai/components/api/smartendpoint/wisej.ai.endpoints.openaiendpoint.md)

Represents an endpoint for connecting to OpenAI services.

{% tabs %}
{% tab title="C#" %}

```csharp
public class OpenAIEndpoint : SmartHttpEndpoint
```

{% endtab %}

{% tab title="VB.NET" %}

```visual-basic
Public Class OpenAIEndpoint
    Inherits SmartHttpEndpoint
```

{% endtab %}
{% endtabs %}

This class is used to interact with OpenAI's API, providing methods to send requests and process responses for both chat completions and embeddings.

## Constructors

### ![](/files/ptrKjmmRoQB76pvrIqh0) OpenAIEndpoint()

Initializes a new instance of the [OpenAIEndpoint](/ai/components/api/smartendpoint/wisej.ai.endpoints.openaiendpoint.md) class with default settings.

The default authentication is set to "Bearer".

## Properties

### ![](/files/ptrKjmmRoQB76pvrIqh0) EmbeddingModel

[String](https://docs.microsoft.com/dotnet/api/system.string): Gets or sets the model used for embeddings. (Default: `"text-embedding-3-small"`)

### ![](/files/ptrKjmmRoQB76pvrIqh0) Model

[String](https://docs.microsoft.com/dotnet/api/system.string): Gets or sets the model used for chat completions. (Default: `"gpt-4o"`)

### ![](/files/ptrKjmmRoQB76pvrIqh0) URL

[String](https://docs.microsoft.com/dotnet/api/system.string): Gets or sets the base URL for the OpenAI API. (Default: `"https://api.openai.com/v1"`)

### ![](/files/ptrKjmmRoQB76pvrIqh0) UseNativeTools

[Boolean](https://docs.microsoft.com/dotnet/api/system.boolean): (Default: `True`)

## Methods

### ![](/files/KL0Ik37djZRr8a07Wopd) AddOptions(message, session)

Adds options to the message for the API request.

| Parameter   | Type                                                          | Description                        |
| ----------- | ------------------------------------------------------------- | ---------------------------------- |
| **message** | [Object](https://docs.microsoft.com/dotnet/api/system.object) | The message to be sent to the API. |
| **session** | [SmartSession](/ai/components/api/smartsession.md)            | The current session context.       |

Sets the temperature to 0.0 and max tokens to the value of [MaxOutputTokens](/ai/components/api/smartendpoint.md#maxoutputtokens).

### ![](/files/KL0Ik37djZRr8a07Wopd) BuildEmbeddingsPayload(inputs)

Builds the payload for an embeddings request.

| Parameter  | Type                                                              | Description                       |
| ---------- | ----------------------------------------------------------------- | --------------------------------- |
| **inputs** | [String\[\]](https://docs.microsoft.com/dotnet/api/system.string) | The input strings to be embedded. |

**Returns:** [Object](https://docs.microsoft.com/dotnet/api/system.object). The constructed payload for the embeddings request.

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception)\
  Thrown when the inputs are null.

### ![](/files/KL0Ik37djZRr8a07Wopd) BuildMessage(message)

Builds the message payload for the API request.

| Parameter   | Type                                                                        | Description                                           |
| ----------- | --------------------------------------------------------------------------- | ----------------------------------------------------- |
| **message** | [Message](/ai/components/api/smartsession/wisej.ai.smartsession.message.md) | The message object containing the content to be sent. |

**Returns:** [Object](https://docs.microsoft.com/dotnet/api/system.object). The constructed message payload.

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception)\
  Thrown when the message is null.

### ![](/files/KL0Ik37djZRr8a07Wopd) GetApiURL()

Constructs the API URL for chat completions.

**Returns:** [String](https://docs.microsoft.com/dotnet/api/system.string). The full API URL for chat completions.

### ![](/files/KL0Ik37djZRr8a07Wopd) GetEmbeddingsURL()

Constructs the API URL for embeddings.

**Returns:** [String](https://docs.microsoft.com/dotnet/api/system.string). The full API URL for embeddings.

### ![](/files/KL0Ik37djZRr8a07Wopd) ReadEmbeddingsResponse(response)

Reads the embeddings from the API response.

| Parameter    | Type                                                                            | Description                         |
| ------------ | ------------------------------------------------------------------------------- | ----------------------------------- |
| **response** | [Response](/ai/components/api/smartendpoint/wisej.ai.smartendpoint.response.md) | The response received from the API. |

**Returns:** [Single\[\]\[\]](https://docs.microsoft.com/dotnet/api/system.single). An array of float arrays representing the embeddings.

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception)\
  Thrown when the response is null.

## Inherited By

| Name                                                                                              | Description                                                                                          |
| ------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- |
| [CerebrasEndpoint](/ai/components/api/smartendpoint/wisej.ai.endpoints.cerebrasendpoint.md)       | Represents a connection to Cerebras endpoints, inheriting from OpenAIEndpoint.                       |
| [DeepSeekEndpoint](/ai/components/api/smartendpoint/wisej.ai.endpoints.deepseekendpoint.md)       | Represents a connection to DeepSeek endpoints, inheriting from OpenAIEndpoint.                       |
| [GroqCloudEndpoint](/ai/components/api/smartendpoint/wisej.ai.endpoints.groqcloudendpoint.md)     | <https://console.groq.com/docs/openai>                                                               |
| [HuggingFaceEndpoint](/ai/components/api/smartendpoint/wisej.ai.endpoints.huggingfaceendpoint.md) | Represents a connection to HuggingFace serverless endpoints for model inference and embeddings.      |
| [LocalAIEndpoint](/ai/components/api/smartendpoint/wisej.ai.endpoints.localaiendpoint.md)         | Represents a connection to LocalAI endpoints, providing access to various AI models and services.    |
| [NvidiaAIEndpoint](/ai/components/api/smartendpoint/wisej.ai.endpoints.nvidiaaiendpoint.md)       | Represents a connection to NVIDIA AI endpoints, providing access to various AI models and services.  |
| [SambaNovaEndpoint](/ai/components/api/smartendpoint/wisej.ai.endpoints.sambanovaendpoint.md)     | Represents a connection to SambaNova endpoints, inheriting from OpenAIEndpoint.                      |
| [TogetherAIEndpoint](/ai/components/api/smartendpoint/wisej.ai.endpoints.togetheraiendpoint.md)   | Represents a connection to TogetherAI endpoints, providing access to various AI models and services. |
| [XAIEndpoint](/ai/components/api/smartendpoint/wisej.ai.endpoints.xaiendpoint.md)                 | Represents a connection to X.AI endpoints, extending the functionality of OpenAIEndpoint.            |


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.wisej.com/ai/components/api/smartendpoint/wisej.ai.endpoints.openaiendpoint.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
