TL;DR – Hand-typing DTOs one 422 at a time slows you down. The official Mistral API OpenAPI spec is 49,000 lines and cannot fit in a 128K context window. The fix was a 296-line community extract and Kiota’s include-path trick. Same model, same request, only the approach changed.
This post is the long-form version of the middle third of the talk, everything between the two demos. It is the part I compressed hardest on stage because it is numbers and screenshots, which is a shame because it contains the actual lesson.
Sick of half-arsed DTOs
Once the basic loop from Part1 worked, the DTOs became the bottleneck. Hand-typed message and choice DTOs fixed one 422 at a time. Every fix revealed a property I had missed or a union variant I did not know existed. Every session started with fixingcasing and enums again, in prompts, over and over again.
// DTOs for the Mistral API
public record ChatCompletionRequest(
[property: JsonPropertyName("model")] string Model,
[property: JsonPropertyName("messages")] ChatMessage[] Messages,
[property: JsonPropertyName("temperature")] float? Temperature = null,
[property: JsonPropertyName("max_tokens")] int? MaxTokens = null,
[property: JsonPropertyName("stream")] bool? Stream = null
);
public record ChatMessage(
[property: JsonPropertyName("role")] string Role,
[property: JsonPropertyName("content")] string Content
);
public record ChatCompletionResponse(
[property: JsonPropertyName("id")] string Id,
[property: JsonPropertyName("object")] string Object,
[property: JsonPropertyName("created")] long Created,
[property: JsonPropertyName("model")] string Model,
[property: JsonPropertyName("choices")] Choice[] Choices,
[property: JsonPropertyName("usage")] Usage Usage
);
public record Choice(
[property: JsonPropertyName("index")] int Index,
[property: JsonPropertyName("message")] ChatMessage Message,
[property: JsonPropertyName("finish_reason")] string FinishReason
);
public record Usage(
[property: JsonPropertyName("prompt_tokens")] int PromptTokens,
[property: JsonPropertyName("completion_tokens")] int CompletionTokens,
[property: JsonPropertyName("total_tokens")] int TotalTokens
);
There is a machine-readable source of truth. The OpenAPI spec. That is when the project stopped being “a chat client” and started being “a client generator’s customer”.
The full spec
Download from docs.mistral.ai/openapi.yaml. 49,000 lines. 1.5 MB. About 300K tokens. Chat completions, Files API, OCR, insertions, all of the things. My context window is approximately128K. It cannot/wouldnot fit so I did the obvious thing anyway. Loaded the whole spec and my client went pop. Prompts hundreds of thousands of tokens deep. Responses slowing and “token maxing”. With the useful answer hidden at the bottom of the payload.
Two lessons came out of the wreck. First, this is why “just give the model the docs” fails in real projects: ground truth has to fit in the window, and the interesting APIs do not. Second, the failure forced the question that saves the whole project: 49,000 lines is what is in it.
The thinking told me
Buried in the model’s failed attempts at code, its reasoning kept naming two things. Kiota, Microsoft’s OpenAPI client generator. Also, a chat-completions-only YAML by API Evangelists. It could not build either. But it knew they existed. It also offered Python libraries and NodeJS utilities, and I even considered generating a console application to chop up the file before choosing to explore instead.
The Telerik Fiddler raw POSTs with 422 typos. First chat client with Memento amnesia and JsonDocument, which made the large model parsing go pop. Second chat client with hand-typed DTOs and a system message, which brought context. Then a chat client plus the big YAML, where the context exploded and .NET regressed. Third chat client with an IMistralService abstraction, plus the small YAML, which works and became YAMLClientLibrary and YAMLClientApplication.
// Client
public class MistralClient
{
private readonly HttpClient _httpClient;
private readonly string _apiKey;
private readonly string _model;
public MistralClient(HttpClient httpClient, IConfiguration config)
{
_httpClient = httpClient;
_apiKey = config["FOEHN_API_KEY"] ?? throw new InvalidOperationException("FOEHN_API_KEY not set");
_model = config["MFOEHN_MODEL"] ?? "mistral-medium-latest";
_httpClient.DefaultRequestHeaders.Authorization = new("Bearer", _apiKey);
}
public async Task<ChatResponse> ChatAsync(ChatRequest request)
{
var response = await _httpClient.PostAsJsonAsync(
"https://api.mistral.ai/v1/chat/completions",
request);
return await response.EnsureSuccessStatusCode().Content.ReadFromJsonAsync<ChatResponse>()
?? throw new InvalidOperationException("Empty response");
}
}
In Retrospect
Since my session (3 days AGO) Mistral.ai doc YAML link has been removed from the API docs page,but is still accessible. Using my “leet” search skills I found the URL of the YAML used by the Mistral Python & Typescript generators use. But I couldn’t access the SpeakeasyAPI endpoint. Some of the changes have been really odd

There are some libraries tghamm(NuGet), tryAGI(NuGet) libraries are based on an older/smaller (roughly 30%) version of the OpenAPI specification, but these weren’t in the spirit of the project.
Calls from New Zealand terminate in Cloudflare, then on to the EU or US. Typical response is 1 to 2 seconds. Occasional tails of 10 to 15 seconds. Bigger models slower, as expected. Fiddler showed the connection path before any application code existed.
There is no Australia East option for Mistral. You pick EU residency or US speed this any distributed API lesson, but the AI hype cycle makes you forget it. Reasoning models spend tokens thinking before they answer. My responses kept truncating mid-code. I escalated the prompt through four rewrites. The winner was “Just code. No thinking.” I dropped the punctuation too. It worked.
Sometimes the fix is asking for less, not explaining more. Negative-space instructions.
The max_tokens dial
Responses cut off mid-line usually are not the model failing. They hit the max_tokens cap. Raise the cap, same request, whole answer. Too small and you waste a full bill on a truncated answer, then retry and pay again. Too big is fine, it is only headroom, except with runaway generation, which bills forever. Tune the cap to your worst realistic response, not your average.
The model matrix
Small. Fast, cheap, occasionally shallow.
Medium. The workhorse. Best cost to quality for this workload.
Large. Made response parsing go pop, literally. Its answers came back so long and so ornately structured that my hand-rolled parsing choked. Beautiful prose, unusable payloads. Small and Medium answer the question. Large writes you an essay about the question.
Codestral. For development text insertions, not this.
Measure with your own workloads. The leaderboards do not know your payload.
.NET drift and prose prompts
I asked for .NET 10 and C# 14. I got .NET 8 idioms. Not malice. The model defaults to the median of its training data. Pleading in the prompt helped a little. Grounding helped completely. This shows up again in a moment as the recurring theme.
Meanwhile the prompts had become a hand-written mini-spec, badly, in prose. “Generate a C# v14 .NET 10 client library for this YAML.” Then a refined version with streaming, synchronous, shared, discriminators. Then “Don’t use NSwag”.
Negative instructions are weak. The model still has to guess what you do want.
System.md, the proto-skill
One attempt generated code that contained a system.md. Static instructions move to a file that rides along on every turn. The prompt shrinks to the request and the conventions persist.
The cache keys from Part 1: the live API reports cache hits, billed at 10%, and neither spec knew. The official one caught half the story. The request side has the plumbing, prompt_cache_key. The response side does not, prompt_tokens_details is missing from the generated interface. The snapshot froze mid-feature.
The exponential increase in speed
More code for me to copy n paste, well lots of code.
4,385 tokens for the client library.
7,756 more for a sample client. So far 11,924
14,332 for basic tool support. So far 26,256
19,999 for smarter searching. So far 46,255.
26,333 for searching with filters. So far 72,588.
31,353 for a slash-command UX. So far 103,941
36,924 for skills. All up 140,865 to get a functional application.
The Human as the Clipboard
The workflow so far: model writes code, I copy it out of the console, paste into a file, build, copy errors back in
Every round-trip has a human where a file operation should be

















