Skip to content

Repository files navigation

Cohere Command A+ on Microsoft Foundry — C# Demo

Cohere Command A+ lands in Microsoft Foundry

Build .NET 10 License: MIT PRs Welcome

A minimal .NET console app that calls the Cohere Command A+ model deployed on Microsoft Foundry using the Azure.AI.Inference SDK. It demonstrates:

  • Passwordless authentication with Entra ID (DefaultAzureCredential) — no API keys in code.
  • A contract analysis prompt that asks for the key terms and risks as JSON.
  • A multilingual prompt (German contract → English JSON) using the same model.

Prerequisites

  • .NET 10 SDK (the project targets net10.0).
  • Azure CLI for sign-in.
  • A Microsoft Foundry resource with the cohere-command-a-plus model deployed.
  • Your identity must have the Cognitive Services User role on the Foundry resource.

NuGet packages

The project references:

Package Version
Azure.AI.Inference 1.0.0-beta.5
Azure.Identity 1.21.0

These are restored automatically on build.

Authentication

The app uses DefaultAzureCredential and forces the token audience to https://cognitiveservices.azure.com/.default (required for Foundry / Cognitive Services endpoints). Managed identity is excluded so local runs use your Azure CLI login.

Sign in before running:

az login

If your identity lacks access, ask an owner to assign the role:

az role assignment create `
  --assignee "<your-user-or-object-id>" `
  --role "Cognitive Services User" `
  --scope "<foundry-resource-id>"

Configuration

The app reads two environment variables:

Variable Required Description
AZURE_AI_CHAT_ENDPOINT Yes The Foundry inference endpoint URL.
AZURE_AI_MODEL No Model/deployment name. Defaults to cohere-command-a-plus.

Set them for the current PowerShell session:

$env:AZURE_AI_CHAT_ENDPOINT = "https://<your-foundry-resource>.services.ai.azure.com/models"
$env:AZURE_AI_MODEL = "cohere-command-a-plus"

The exact endpoint format depends on your Foundry deployment. Copy it from the deployment's Endpoint field in the Foundry / Azure AI portal.

Run the demo

Clone the repo, set the endpoint (see Configuration), sign in and run:

git clone https://github.com/taswar/CohereCommandAPlusDemo.git
cd CohereCommandAPlusDemo
az login
dotnet run

What it does

  1. English contract analysis — sends a software licensing agreement excerpt and asks the model to return structured JSON (parties, term, liability cap, risks, etc.).
  2. Multilingual analysis — clears the conversation, then sends a German service agreement and asks for the analysis back in English JSON.

Both responses are printed to the console.

Troubleshooting

Symptom Fix
Set AZURE_AI_CHAT_ENDPOINT environment variable. Set the endpoint variable (see Configuration).
401 / 403 authorization errors Run az login; ensure you have the Cognitive Services User role on the resource.
404 model not found Verify AZURE_AI_MODEL matches your deployment name.
Token audience errors The app already forces the cognitiveservices.azure.com scope — confirm the endpoint is a Foundry/Cognitive Services endpoint.

Project structure

CohereCommandAPlusDemo/
├── .github/workflows/dotnet.yml   Build workflow
├── CohereCommandAPlusDemo.csproj  .NET 10 project and package references
├── Program.cs                     Client setup and both prompts
├── CONTRIBUTING.md                How to contribute
├── LICENSE                        MIT license
└── README.md

License

This project is licensed under the MIT License. See LICENSE.