因為現在模型疊代速度很快,會一直有新模型或是新版本,因此就會開始有管理上的問題,我們會需要確保模型的淘汰時間跟部署狀態,雖然可以從 Azure AI Foundry 看到部署的模型跟淘汰的時間,但是我們建立的 Account 很多的時候就會變的麻煩了,此時我們可以透過 Api 來處理跟匯總這些資料,本文就來實做檢查所有部署的模型資料跟淘汰時間。

說明
在 Azure AI Foundry 模型部署可以看到如底下的資訊,但是假設我們建立多個 OpenAI Account 的話就得切換之後逐一確認,因此透過 Api 來列出所有的模型部署跟資訊。

因為微軟並沒有提供模型的淘汰時間的 Api,僅有官方文件有說明,因此需要先從文件把相關資料整理出來。
先定義好模型相關的資料。
public class ModelInfo
{
public string Model { get; set; }
public string Version { get; set; }
public string LifecycleStatus { get; set; }
public DateTime? RetirementDate { get; set; }
public string ReplacementModel { get; set; }
}
寫一個方法來查詢模型淘汰的狀況。
底下方法僅到本文撰寫時候有的資料,後續有新版本模型時候請根據文件資料確定為最新的資料。
public ModelInfo GetModelInfo(string modelName, string modelVersion)
{
var models = new List<ModelInfo>
{
new ModelInfo { Model = "computer-use-preview", Version = "2025-03-11", LifecycleStatus = "Preview", RetirementDate = new DateTime(2025, 10, 10), ReplacementModel = "" },
new ModelInfo { Model = "gpt-35-turbo", Version = "1106", LifecycleStatus = "Generally Available", RetirementDate = new DateTime(2025, 10, 15), ReplacementModel = "gpt-4.1-mini" },
new ModelInfo { Model = "gpt-35-turbo", Version = "0125", LifecycleStatus = "Generally Available", RetirementDate = new DateTime(2025, 10, 15), ReplacementModel = "gpt-4.1-mini" },
new ModelInfo { Model = "gpt-3.5-turbo-instruct", Version = "0914", LifecycleStatus = "Generally Available", RetirementDate = new DateTime(2025, 10, 15), ReplacementModel = "" },
new ModelInfo { Model = "gpt-4", Version = "turbo-2024-04-09", LifecycleStatus = "Generally Available", RetirementDate = new DateTime(2025, 10, 15), ReplacementModel = "gpt-4.1" },
new ModelInfo { Model = "o1-mini", Version = "2024-09-12", LifecycleStatus = "Generally Available", RetirementDate = new DateTime(2025, 10, 27), ReplacementModel = "o4-mini" },
new ModelInfo { Model = "gpt-5-chat", Version = "2025-08-07", LifecycleStatus = "Preview", RetirementDate = new DateTime(2025, 11, 15), ReplacementModel = "" },
new ModelInfo { Model = "model-router", Version = "2025-05-19", LifecycleStatus = "Preview", RetirementDate = new DateTime(2025, 11, 30), ReplacementModel = "" },
new ModelInfo { Model = "model-router", Version = "2025-08-07", LifecycleStatus = "Preview", RetirementDate = new DateTime(2025, 11, 30), ReplacementModel = "" },
new ModelInfo { Model = "o3-mini", Version = "2025-01-31", LifecycleStatus = "Generally Available", RetirementDate = new DateTime(2026, 2, 1), ReplacementModel = "o4-mini" },
new ModelInfo { Model = "gpt-4o", Version = "2024-05-13", LifecycleStatus = "Generally Available", RetirementDate = new DateTime(2026, 2, 27), ReplacementModel = "gpt-4.1" },
new ModelInfo { Model = "gpt-4o-mini", Version = "2024-07-18", LifecycleStatus = "Generally Available", RetirementDate = new DateTime(2026, 2, 27), ReplacementModel = "gpt-4.1-mini" },
new ModelInfo { Model = "gpt-4o", Version = "2024-08-06", LifecycleStatus = "Generally Available", RetirementDate = new DateTime(2026, 2, 27), ReplacementModel = "gpt-4.1" },
new ModelInfo { Model = "gpt-4o", Version = "2024-11-20", LifecycleStatus = "Generally Available", RetirementDate = new DateTime(2026, 3, 1), ReplacementModel = "gpt-4.1" },
new ModelInfo { Model = "gpt-4.1", Version = "2025-04-14", LifecycleStatus = "Generally Available", RetirementDate = new DateTime(2026, 4, 11), ReplacementModel = "" },
new ModelInfo { Model = "gpt-4.1-mini", Version = "2025-04-14", LifecycleStatus = "Generally Available", RetirementDate = new DateTime(2026, 4, 11), ReplacementModel = "" },
new ModelInfo { Model = "gpt-4.1-nano", Version = "2025-04-14", LifecycleStatus = "Generally Available", RetirementDate = new DateTime(2026, 4, 11), ReplacementModel = "" },
new ModelInfo { Model = "o4-mini", Version = "2025-04-16", LifecycleStatus = "Generally Available", RetirementDate = new DateTime(2026, 4, 11), ReplacementModel = "" },
new ModelInfo { Model = "o3", Version = "2025-04-16", LifecycleStatus = "Generally Available", RetirementDate = new DateTime(2026, 4, 11), ReplacementModel = "" },
new ModelInfo { Model = "o3-pro", Version = "2025-06-10", LifecycleStatus = "Generally Available", RetirementDate = new DateTime(2026, 6, 18), ReplacementModel = "" },
new ModelInfo { Model = "codex-mini", Version = "2025-05-16", LifecycleStatus = "Generally Available", RetirementDate = new DateTime(2026, 6, 19), ReplacementModel = "" },
new ModelInfo { Model = "o3-deep-research", Version = "2025-06-26", LifecycleStatus = "Generally Available", RetirementDate = new DateTime(2026, 6, 26), ReplacementModel = "" },
new ModelInfo { Model = "o1", Version = "2024-12-17", LifecycleStatus = "Generally Available", RetirementDate = new DateTime(2026, 7, 15), ReplacementModel = "" },
new ModelInfo { Model = "gpt-5", Version = "2025-08-07", LifecycleStatus = "Generally Available", RetirementDate = new DateTime(2026, 8, 7), ReplacementModel = "" },
new ModelInfo { Model = "gpt-5-mini", Version = "2025-08-07", LifecycleStatus = "Generally Available", RetirementDate = new DateTime(2026, 8, 7), ReplacementModel = "" },
new ModelInfo { Model = "gpt-5-nano", Version = "2025-08-07", LifecycleStatus = "Generally Available", RetirementDate = new DateTime(2026, 8, 7), ReplacementModel = "" },
new ModelInfo { Model = "gpt-4o-realtime-preview", Version = "2025-06-03", LifecycleStatus = "Preview", RetirementDate = new DateTime(2025, 9, 1), ReplacementModel = "" },
new ModelInfo { Model = "gpt-4o-mini-realtime-preview", Version = "2024-12-17", LifecycleStatus = "Preview", RetirementDate = new DateTime(2025, 9, 17), ReplacementModel = "" },
new ModelInfo { Model = "gpt-4o-realtime-preview", Version = "2024-12-17", LifecycleStatus = "Preview", RetirementDate = new DateTime(2025, 9, 17), ReplacementModel = "" },
new ModelInfo { Model = "gpt-4o-audio-preview", Version = "2024-12-17", LifecycleStatus = "Preview", RetirementDate = new DateTime(2025, 9, 17), ReplacementModel = "" },
new ModelInfo { Model = "gpt-4o-audio-preview", Version = "2024-12-17", LifecycleStatus = "Preview", RetirementDate = new DateTime(2025, 9, 17), ReplacementModel = "" },
new ModelInfo { Model = "gpt-4o-transcribe", Version = "2025-03-20", LifecycleStatus = "Preview", RetirementDate = new DateTime(2025, 9, 17), ReplacementModel = "" },
new ModelInfo { Model = "gpt-4o-mini-tts", Version = "2025-03-20", LifecycleStatus = "Preview", RetirementDate = new DateTime(2025, 9, 17), ReplacementModel = "" },
new ModelInfo { Model = "gpt-4o-mini-transcribe", Version = "2025-03-20", LifecycleStatus = "Preview", RetirementDate = new DateTime(2025, 9, 17), ReplacementModel = "" },
new ModelInfo { Model = "tts", Version = "001", LifecycleStatus = "Generally Available", RetirementDate = new DateTime(2026, 2, 1), ReplacementModel = "" },
new ModelInfo { Model = "tts-hd", Version = "001", LifecycleStatus = "Generally Available", RetirementDate = new DateTime(2026, 2, 1), ReplacementModel = "" },
new ModelInfo { Model = "whisper", Version = "001", LifecycleStatus = "Generally Available", RetirementDate = new DateTime(2026, 2, 1), ReplacementModel = "" },
new ModelInfo { Model = "sora", Version = "2025-05-02", LifecycleStatus = "Preview", RetirementDate = new DateTime(2025, 10, 15), ReplacementModel = "" },
new ModelInfo { Model = "dalle-3", Version = "3", LifecycleStatus = "Generally Available", RetirementDate = new DateTime(2025, 10, 31), ReplacementModel = "" },
new ModelInfo { Model = "gpt-image-1", Version = "2025-04-15", LifecycleStatus = "Preview", RetirementDate = new DateTime(2025, 10, 31), ReplacementModel = "" },
new ModelInfo { Model = "text-embedding-ada-002", Version = "2", LifecycleStatus = "Generally Available", RetirementDate = new DateTime(2026, 4, 30), ReplacementModel = "text-embedding-3-small or text-embedding-3-large" },
new ModelInfo { Model = "text-embedding-ada-002", Version = "1", LifecycleStatus = "Generally Available", RetirementDate = new DateTime(2026, 4, 30), ReplacementModel = "text-embedding-3-small or text-embedding-3-large" },
new ModelInfo { Model = "text-embedding-3-small", Version = "1", LifecycleStatus = "Generally Available", RetirementDate = new DateTime(2026, 4, 30), ReplacementModel = "" },
new ModelInfo { Model = "text-embedding-3-large", Version = "1", LifecycleStatus = "Generally Available", RetirementDate = new DateTime(2026, 4, 30), ReplacementModel = "" },
};
return models.Where(x => x.Model == modelName && x.Version == modelVersion).SingleOrDefault();
}
接下來撰寫主程式,需要先加入兩個 Azure 的套件。
dotnet add package Azure.Identity --version 1.15.0
dotnet add package Azure.ResourceManager.CognitiveServices --version 1.5.1
主程式如下,會先把訂閱列出來,再去查詢所有的 CognitiveServices,並且篩選出 kind 是 OpenAI 和 AIServices 的項目,這兩個類型都會包含模型的部署。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using Azure.Core;
using Azure.ResourceManager;
using Azure.ResourceManager.CognitiveServices;
using Azure.ResourceManager.Resources;
using System.Threading.Tasks;
async Task Main()
{
var deploymentInfos = new List<DeploymentInfo>();
TokenCredential cred = new DefaultAzureCredential();
ArmClient client = new ArmClient(cred);
await foreach (SubscriptionResource sub in client.GetSubscriptions().GetAllAsync())
{
string filter = "resourceType eq 'Microsoft.CognitiveServices/accounts'";
await foreach (var gen in sub.GetGenericResourcesAsync(filter: filter))
{
if (gen.Data.Kind == "OpenAI" || gen.Data.Kind == "AIServices")
{
CognitiveServicesAccountResource cognitiveServicesAccount = client.GetCognitiveServicesAccountResource(gen.Id);
CognitiveServicesAccountDeploymentCollection collection = cognitiveServicesAccount.GetCognitiveServicesAccountDeployments();
await foreach (CognitiveServicesAccountDeploymentResource item in collection.GetAllAsync())
{
CognitiveServicesAccountDeploymentData resourceData = item.Data;
var modelInfo = GetModelInfo(resourceData.Properties.Model.Name, resourceData.Properties.Model.Version);
deploymentInfos.Add(new DeploymentInfo()
{
SubscriptionId = sub.Data.SubscriptionId,
SubscriptionName = sub.Data.DisplayName,
ResourceGroup = gen.Id.ResourceGroupName,
AccountName = gen.Id.Name,
DeploymentName = resourceData.Name,
DeploymentSku = resourceData.Sku.Name,
ModelName = resourceData.Properties.Model.Name,
ModelVersion = resourceData.Properties.Model.Version,
ProvisioningState = resourceData.Properties.ProvisioningState.ToString(),
VersionUpgradeOption = resourceData.Properties.VersionUpgradeOption.ToString(),
RetirementDate = modelInfo?.RetirementDate,
ReplacementModel = modelInfo?.ReplacementModel
});
}
}
}
}
deploymentInfos.Dump(); // LINQPad 方法
}
執行之後就可以看到帳號底下所有的模型資訊了。

其中我還有特別把模型版本升級原則也一併列出來,這樣就可以判斷是否會自行升級,避免後續沒自動升級導致模型 Disable 了。

結論
透過 Api 我們可以把模型部署相關資料給列出來,後續就可以針對這些資料來撰寫警示相關的排程,就可以在模型要淘汰前進快處理或是確認,避免影響到服務的運行。