Skip to content

Conversation

@qkfang
Copy link
Contributor

@qkfang qkfang commented Jan 2, 2026

the provided c# sample code for openai responses api does not work and have multiple compilations errors, see below.
image

  • have update the sample code based on latest openai nuget package 2.8.0, also referenced latest openai repo documentation
    https://www.nuget.org/packages/OpenAI
    https://github.com/openai/openai-dotnet/blob/main/examples/Responses/Example01_SimpleResponse.cs

  • add comments to highlight the model must support responses api

  • add sample to use APIKey (oauth is much harder to get it working correctly)

  • disabled warning from openai nuget saying "'OpenAI.Responses.ResponsesClient' is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.", it is from package

  • can compile correctly and tested working with foundry gpt-5.2-chat model.

image

@prmerger-automator
Copy link
Contributor

@qkfang : Thanks for your contribution! The author(s) and reviewer(s) have been notified to review your proposed change.

@learn-build-service-prod
Copy link
Contributor

Learn Build status updates of commit 38ec1c8:

✅ Validation status: passed

File Status Preview URL Details
articles/ai-foundry/how-to/develop/sdk-overview.md ✅Succeeded

For more details, please refer to the build report.

@learn-build-service-prod
Copy link
Contributor

Learn Build status updates of commit 061c14d:

✅ Validation status: passed

File Status Preview URL Details
articles/ai-foundry/how-to/develop/sdk-overview.md ✅Succeeded

For more details, please refer to the build report.

@v-regandowner
Copy link
Contributor

@ms-johnalex

Can you review the proposed changes?

IMPORTANT: When the changes are ready for publication, adding a #sign-off comment is the best way to signal that the PR is ready for the review team to merge.

#label:"aq-pr-triaged"
@MicrosoftDocs/public-repo-pr-review-team

@prmerger-automator prmerger-automator bot added the aq-pr-triaged C+L Pull Request Review Team label label Jan 2, 2026
@v-regandowner v-regandowner requested a review from Copilot January 2, 2026 16:36
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR attempts to fix compilation errors in the C# sample code for the OpenAI Responses API by updating it to work with OpenAI NuGet package version 2.8.0. The changes include adding package installation instructions, updating using statements, modifying the client initialization code, adding pragma warnings to suppress experimental API warnings, and including example usage code.

Key Changes:

  • Updated package installation to explicitly include Azure.Identity and Azure.Core
  • Modified ResponsesClient instantiation with new constructor parameters and authentication options
  • Added #pragma warning directives to suppress OPENAI001 warnings about experimental APIs

Comment on lines 346 to 351
var projectClient = new ResponsesClient(
model: "<YOUR-DEPLOYMENT-NAME>", //e.g. gpt-5.2-chat, must be a model that supports Responses API
authenticationPolicy: tokenPolicy, // if use EntraID
// credential: new ApiKeyCredential("<YOUR-KEY>") // if use APIKEY
clientOptions
);
Copy link

Copilot AI Jan 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ResponsesClient constructor call has invalid syntax. The parameters are incorrectly mixed between named and positional arguments. The third parameter 'clientOptions' is not properly named and the second parameter 'authenticationPolicy' appears to be invalid for this constructor.

Based on the OpenAI SDK patterns shown in other parts of the codebase (e.g., articles/ai-foundry/foundry-models/how-to/generate-responses.md:98-100), the recommended approach is to use AIProjectClient with GetProjectResponsesClientForModel instead of directly instantiating ResponsesClient.

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@learn-build-service-prod
Copy link
Contributor

Learn Build status updates of commit 4af8a59:

✅ Validation status: passed

File Status Preview URL Details
articles/ai-foundry/how-to/develop/sdk-overview.md ✅Succeeded

For more details, please refer to the build report.

Updated the description of the code snippet for clarity.
@learn-build-service-prod
Copy link
Contributor

Learn Build status updates of commit 8370b0f:

✅ Validation status: passed

File Status Preview URL Details
articles/ai-foundry/how-to/develop/sdk-overview.md ✅Succeeded

For more details, please refer to the build report.

@learn-build-service-prod
Copy link
Contributor

Learn Build status updates of commit 3d8354e:

✅ Validation status: passed

File Status Preview URL Details
articles/ai-foundry/how-to/develop/sdk-overview.md ✅Succeeded

For more details, please refer to the build report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants