@@ -0,0 +1,100 @@
1+// models.dev metadata, embedded at build time. Refresh with
2+// `python3 tools/gen_models_dev.py`.
3+
4+const std = @import("std");
5+
6+/// The raw models.dev document, filtered to the providers this agent talks to.
7+pub const raw = @embedFile("models_dev.json");
8+
9+pub const Info = struct {
10+ name: []const u8,
11+ api: []const u8,
12+ base_url: []const u8,
13+ images: bool,
14+ reasoning: bool,
15+ context: u64,
16+ max_output: u64,
17+ effort: []const []const u8,
18+ cost_input: f64,
19+ cost_output: f64,
20+ cost_cache_read: f64,
21+};
22+
23+const wires = [_][2][]const u8{
24+ .{ "@ai-sdk/openai-compatible", "openai-completions" },
25+ .{ "@ai-sdk/openai", "openai-responses" },
26+ .{ "@ai-sdk/anthropic", "anthropic-messages" },
27+ .{ "@ai-sdk/google", "google-generative-ai" },
28+};
29+
30+fn wire(npm: []const u8) ?[]const u8 {
31+ for (wires) |w| {
32+ if (std.mem.eql(u8, w[0], npm)) return w[1];
33+ }
34+ return null;
35+}
36+
37+const Effort = struct { type: []const u8 = "", values: []const []const u8 = &.{} };
38+const Limit = struct { context: u64 = 0, output: u64 = 0 };
39+const Cost = struct { input: f64 = 0, output: f64 = 0, cache_read: f64 = 0 };
40+const Package = struct { npm: []const u8 = "" };
41+
42+const Model = struct {
43+ name: []const u8 = "",
44+ attachment: bool = false,
45+ reasoning: bool = false,
46+ reasoning_options: []const Effort = &.{},
47+ limit: Limit = .{},
48+ cost: Cost = .{},
49+ provider: ?Package = null,
50+};
51+
52+const Provider = struct {
53+ api: []const u8 = "",
54+ npm: []const u8 = "",
55+ models: std.json.ArrayHashMap(Model) = .{},
56+};
57+
58+const File = std.json.ArrayHashMap(Provider);
59+
60+/// A parsed models.dev document. The provider listing and each model's wire,
61+/// base URL and metadata all come from here.
62+pub const Db = struct {
63+ file: File,
64+
65+ pub fn open(a: std.mem.Allocator) !Db {
66+ return .{ .file = try std.json.parseFromSliceLeaky(File, a, raw, .{ .ignore_unknown_fields = true }) };
67+ }
68+
69+ pub fn baseUrl(self: Db, provider_id: []const u8) ?[]const u8 {
70+ const p = self.file.map.get(provider_id) orelse return null;
71+ if (p.api.len == 0) return null;
72+ return std.mem.trimEnd(u8, p.api, "/");
73+ }
74+
75+ pub fn info(self: Db, provider_id: []const u8, model_id: []const u8) ?Info {
76+ const p = self.file.map.get(provider_id) orelse return null;
77+ if (p.api.len == 0) return null;
78+ const m = p.models.map.get(model_id) orelse return null;
79+ return .{
80+ .name = if (m.name.len > 0) m.name else model_id,
81+ .api = wire(if (m.provider) |pkg| pkg.npm else p.npm) orelse return null,
82+ .base_url = std.mem.trimEnd(u8, p.api, "/"),
83+ .images = m.attachment,
84+ .reasoning = m.reasoning,
85+ .context = m.limit.context,
86+ .max_output = m.limit.output,
87+ .effort = effortOf(m),
88+ .cost_input = m.cost.input,
89+ .cost_output = m.cost.output,
90+ .cost_cache_read = m.cost.cache_read,
91+ };
92+ }
93+};
94+
95+fn effortOf(m: Model) []const []const u8 {
96+ for (m.reasoning_options) |opt| {
97+ if (std.mem.eql(u8, opt.type, "effort")) return opt.values;
98+ }
99+ return &.{};
100+}