OpenAIExtensions Methods
Class Methods 5 members
Provides extension methods for adding OpenAI Model resources to the application model.
AddModel(IResourceBuilder<OpenAIResource>, string, string) Section titled AddModel(IResourceBuilder<OpenAIResource>, string, string) extension IResourceBuilder<OpenAIModelResource> Adds an OpenAI Model child to the provided OpenAI resource.
public static class OpenAIExtensions{ public static IResourceBuilder<OpenAIModelResource> AddModel( this IResourceBuilder<OpenAIResource> builder, string name, string model) { // ... }}Parameters
builder IResourceBuilder<OpenAIResource> The OpenAI resource builder. name string The name of the model resource. This name is used as the connection string name. model string The model identifier, e.g., "gpt-4o-mini". Returns
IResourceBuilder<OpenAIModelResource> The model resource builder. AddOpenAI(IDistributedApplicationBuilder, string) Section titled AddOpenAI(IDistributedApplicationBuilder, string) extension IResourceBuilder<OpenAIResource> Adds an OpenAI parent resource that can host multiple models.
public static class OpenAIExtensions{ public static IResourceBuilder<OpenAIResource> AddOpenAI( this IDistributedApplicationBuilder builder, string name) { // ... }}Parameters
builder IDistributedApplicationBuilder The Hosting.IDistributedApplicationBuilder. name string The name of the OpenAI resource. Returns
IResourceBuilder<OpenAIResource> The OpenAI resource builder. WithApiKey(IResourceBuilder<OpenAIResource>, IResourceBuilder<ParameterResource>) Section titled WithApiKey(IResourceBuilder<OpenAIResource>, IResourceBuilder<ParameterResource>) extension IResourceBuilder<OpenAIResource> Configures the API key for the OpenAI parent resource from a parameter.
public static class OpenAIExtensions{ public static IResourceBuilder<OpenAIResource> WithApiKey( this IResourceBuilder<OpenAIResource> builder, IResourceBuilder<ParameterResource> apiKey) { // ... }}Parameters
builder IResourceBuilder<OpenAIResource> apiKey IResourceBuilder<ParameterResource> WithEndpoint(IResourceBuilder<OpenAIResource>, string) Section titled WithEndpoint(IResourceBuilder<OpenAIResource>, string) extension IResourceBuilder<OpenAIResource> Sets a custom OpenAI-compatible service endpoint URI on the parent resource.
public static class OpenAIExtensions{ public static IResourceBuilder<OpenAIResource> WithEndpoint( this IResourceBuilder<OpenAIResource> builder, string endpoint) { // ... }}Parameters
builder IResourceBuilder<OpenAIResource> The OpenAI parent resource builder. endpoint string The endpoint URI, e.g., https://mygateway.example.com/v1. WithHealthCheck(IResourceBuilder<OpenAIModelResource>) Section titled WithHealthCheck(IResourceBuilder<OpenAIModelResource>) extension IResourceBuilder<OpenAIModelResource> Adds a health check to the OpenAI Model resource.
public static class OpenAIExtensions{ public static IResourceBuilder<OpenAIModelResource> WithHealthCheck( this IResourceBuilder<OpenAIModelResource> builder) { // ... }}Parameters
builder IResourceBuilder<OpenAIModelResource> The resource builder. Returns
IResourceBuilder<OpenAIModelResource> The resource builder. Remarks
This method adds a health check that verifies the OpenAI endpoint is accessible, the API key is valid, and the specified model is available. The health check will:
Because health checks are included in the rate limit of the OpenAI API, it is recommended to use this health check sparingly, such as when you are having issues understanding the reason the model is not working as expected. Furthermore, the health check will run a single time per application instance.