Chuyển đến nội dung chính

Bài đăng

Hiển thị các bài đăng có nhãn Cost

Prompt caching on mobile AI calls — hướng dẫn Flutter

Stable system prefixes can cut AI costs dramatically. Bài này chuyển quan sát đó thành một mô hình nhỏ để bạn có thể kiểm thử, đo lường và giữ cho code dễ bảo trì khi app lớn lên. Vấn đề cốt lõi Prefix stability, cost cuts, and cache invalidation. Câu hỏi hữu ích không phải API hay pattern có đẹp riêng lẻ hay không, mà là state nằm ở đâu, boundary nào chịu trách nhiệm khi lỗi xảy ra, và người dùng phục hồi thế nào khi happy path biến mất. Mô hình thực tế Design prompts so the expensive prefix is cacheable. Hãy bắt đầu bằng một owner rõ ràng cho behavior. Widget chỉ nên render và phát intent; IO, persistence, permission và retry nên nằm sau một interface nhỏ. Nhờ vậy bạn có seam để fake trong test và một chỗ ghi lại các dữ kiện cần theo dõi ở production. Trong app Flutter, boundary thường có dạng: Widget phát intent như load, submit, refresh hoặc retry. Controller hoặc use case validate intent rồi gọi boundary. Boundary trả về data có kiểu hoặc failure có kiểu, không trả stri...

Prompt caching on mobile AI calls

Stable system prefixes can cut AI costs dramatically. This article turns that observation into a small implementation model you can test, measure, and keep boring when the app grows. The problem in one sentence Prefix stability, cost cuts, and cache invalidation. The useful question is not whether the API or pattern looks elegant in isolation. It is where state lives, which boundary owns failure, and how a user recovers when the happy path disappears. A practical model Design prompts so the expensive prefix is cacheable. Start with one explicit owner for the behavior. Keep widgets responsible for rendering and user intent; keep IO, persistence, permissions, and retries behind a small interface. That gives you a seam for a fake in tests and a place to record the facts that matter in production. For a Flutter app, the boundary usually looks like this: The widget emits an intent such as load, submit, refresh, or retry. A controller or use case validates the intent and calls the ...

Mobile observability cost control — hướng dẫn Flutter

Telemetry can cost more than hosting if left unchecked. Bài này chuyển quan sát đó thành một mô hình nhỏ để bạn có thể kiểm thử, đo lường và giữ cho code dễ bảo trì khi app lớn lên. Vấn đề cốt lõi Sampling, cardinality, and what to keep forever. Câu hỏi hữu ích không phải API hay pattern có đẹp riêng lẻ hay không, mà là state nằm ở đâu, boundary nào chịu trách nhiệm khi lỗi xảy ra, và người dùng phục hồi thế nào khi happy path biến mất. Mô hình thực tế Sample traces; keep 100% of errors. Hãy bắt đầu bằng một owner rõ ràng cho behavior. Widget chỉ nên render và phát intent; IO, persistence, permission và retry nên nằm sau một interface nhỏ. Nhờ vậy bạn có seam để fake trong test và một chỗ ghi lại các dữ kiện cần theo dõi ở production. Trong app Flutter, boundary thường có dạng: Widget phát intent như load, submit, refresh hoặc retry. Controller hoặc use case validate intent rồi gọi boundary. Boundary trả về data có kiểu hoặc failure có kiểu, không trả string chỉ dành cho log...

Mobile observability cost control

Telemetry can cost more than hosting if left unchecked. This article turns that observation into a small implementation model you can test, measure, and keep boring when the app grows. The problem in one sentence Sampling, cardinality, and what to keep forever. The useful question is not whether the API or pattern looks elegant in isolation. It is where state lives, which boundary owns failure, and how a user recovers when the happy path disappears. A practical model Sample traces; keep 100% of errors. Start with one explicit owner for the behavior. Keep widgets responsible for rendering and user intent; keep IO, persistence, permissions, and retries behind a small interface. That gives you a seam for a fake in tests and a place to record the facts that matter in production. For a Flutter app, the boundary usually looks like this: The widget emits an intent such as load, submit, refresh, or retry. A controller or use case validates the intent and calls the boundary. The boun...

Model routing and cascades for mobile AI — hướng dẫn Flutter

Not every request needs the largest model. Bài này chuyển quan sát đó thành một mô hình nhỏ để bạn có thể kiểm thử, đo lường và giữ cho code dễ bảo trì khi app lớn lên. Vấn đề cốt lõi Cheap first, escalate on uncertainty, measure quality. Câu hỏi hữu ích không phải API hay pattern có đẹp riêng lẻ hay không, mà là state nằm ở đâu, boundary nào chịu trách nhiệm khi lỗi xảy ra, và người dùng phục hồi thế nào khi happy path biến mất. Mô hình thực tế Classify difficulty; escalate only when confidence is low. Hãy bắt đầu bằng một owner rõ ràng cho behavior. Widget chỉ nên render và phát intent; IO, persistence, permission và retry nên nằm sau một interface nhỏ. Nhờ vậy bạn có seam để fake trong test và một chỗ ghi lại các dữ kiện cần theo dõi ở production. Trong app Flutter, boundary thường có dạng: Widget phát intent như load, submit, refresh hoặc retry. Controller hoặc use case validate intent rồi gọi boundary. Boundary trả về data có kiểu hoặc failure có kiểu, không trả string ...

Model routing and cascades for mobile AI

Not every request needs the largest model. This article turns that observation into a small implementation model you can test, measure, and keep boring when the app grows. The problem in one sentence Cheap first, escalate on uncertainty, measure quality. The useful question is not whether the API or pattern looks elegant in isolation. It is where state lives, which boundary owns failure, and how a user recovers when the happy path disappears. A practical model Classify difficulty; escalate only when confidence is low. Start with one explicit owner for the behavior. Keep widgets responsible for rendering and user intent; keep IO, persistence, permissions, and retries behind a small interface. That gives you a seam for a fake in tests and a place to record the facts that matter in production. For a Flutter app, the boundary usually looks like this: The widget emits an intent such as load, submit, refresh, or retry. A controller or use case validates the intent and calls the bou...

Prompt caching on mobile AI calls — hướng dẫn Flutter

Stable system prefixes can cut AI costs dramatically. Bài này chuyển quan sát đó thành một mô hình nhỏ để bạn có thể kiểm thử, đo lường và giữ cho code dễ bảo trì khi app lớn lên. Vấn đề cốt lõi Prefix stability, cost cuts, and cache invalidation. Câu hỏi hữu ích không phải API hay pattern có đẹp riêng lẻ hay không, mà là state nằm ở đâu, boundary nào chịu trách nhiệm khi lỗi xảy ra, và người dùng phục hồi thế nào khi happy path biến mất. Mô hình thực tế Design prompts so the expensive prefix is cacheable. Hãy bắt đầu bằng một owner rõ ràng cho behavior. Widget chỉ nên render và phát intent; IO, persistence, permission và retry nên nằm sau một interface nhỏ. Nhờ vậy bạn có seam để fake trong test và một chỗ ghi lại các dữ kiện cần theo dõi ở production. Trong app Flutter, boundary thường có dạng: Widget phát intent như load, submit, refresh hoặc retry. Controller hoặc use case validate intent rồi gọi boundary. Boundary trả về data có kiểu hoặc failure có kiểu, không trả stri...

Mobile observability cost control — hướng dẫn Flutter

Telemetry can cost more than hosting if left unchecked. Bài này chuyển quan sát đó thành một mô hình nhỏ để bạn có thể kiểm thử, đo lường và giữ cho code dễ bảo trì khi app lớn lên. Vấn đề cốt lõi Sampling, cardinality, and what to keep forever. Câu hỏi hữu ích không phải API hay pattern có đẹp riêng lẻ hay không, mà là state nằm ở đâu, boundary nào chịu trách nhiệm khi lỗi xảy ra, và người dùng phục hồi thế nào khi happy path biến mất. Mô hình thực tế Sample traces; keep 100% of errors. Hãy bắt đầu bằng một owner rõ ràng cho behavior. Widget chỉ nên render và phát intent; IO, persistence, permission và retry nên nằm sau một interface nhỏ. Nhờ vậy bạn có seam để fake trong test và một chỗ ghi lại các dữ kiện cần theo dõi ở production. Trong app Flutter, boundary thường có dạng: Widget phát intent như load, submit, refresh hoặc retry. Controller hoặc use case validate intent rồi gọi boundary. Boundary trả về data có kiểu hoặc failure có kiểu, không trả string chỉ dành cho log...

Model routing and cascades for mobile AI — hướng dẫn Flutter

Not every request needs the largest model. Bài này chuyển quan sát đó thành một mô hình nhỏ để bạn có thể kiểm thử, đo lường và giữ cho code dễ bảo trì khi app lớn lên. Vấn đề cốt lõi Cheap first, escalate on uncertainty, measure quality. Câu hỏi hữu ích không phải API hay pattern có đẹp riêng lẻ hay không, mà là state nằm ở đâu, boundary nào chịu trách nhiệm khi lỗi xảy ra, và người dùng phục hồi thế nào khi happy path biến mất. Mô hình thực tế Classify difficulty; escalate only when confidence is low. Hãy bắt đầu bằng một owner rõ ràng cho behavior. Widget chỉ nên render và phát intent; IO, persistence, permission và retry nên nằm sau một interface nhỏ. Nhờ vậy bạn có seam để fake trong test và một chỗ ghi lại các dữ kiện cần theo dõi ở production. Trong app Flutter, boundary thường có dạng: Widget phát intent như load, submit, refresh hoặc retry. Controller hoặc use case validate intent rồi gọi boundary. Boundary trả về data có kiểu hoặc failure có kiểu, không trả string ...

Prompt caching on mobile AI calls

Stable system prefixes can cut AI costs dramatically. This article turns that observation into a small implementation model you can test, measure, and keep boring when the app grows. The problem in one sentence Prefix stability, cost cuts, and cache invalidation. The useful question is not whether the API or pattern looks elegant in isolation. It is where state lives, which boundary owns failure, and how a user recovers when the happy path disappears. A practical model Design prompts so the expensive prefix is cacheable. Start with one explicit owner for the behavior. Keep widgets responsible for rendering and user intent; keep IO, persistence, permissions, and retries behind a small interface. That gives you a seam for a fake in tests and a place to record the facts that matter in production. For a Flutter app, the boundary usually looks like this: The widget emits an intent such as load, submit, refresh, or retry. A controller or use case validates the intent and calls the ...

Mobile observability cost control

Telemetry can cost more than hosting if left unchecked. This article turns that observation into a small implementation model you can test, measure, and keep boring when the app grows. The problem in one sentence Sampling, cardinality, and what to keep forever. The useful question is not whether the API or pattern looks elegant in isolation. It is where state lives, which boundary owns failure, and how a user recovers when the happy path disappears. A practical model Sample traces; keep 100% of errors. Start with one explicit owner for the behavior. Keep widgets responsible for rendering and user intent; keep IO, persistence, permissions, and retries behind a small interface. That gives you a seam for a fake in tests and a place to record the facts that matter in production. For a Flutter app, the boundary usually looks like this: The widget emits an intent such as load, submit, refresh, or retry. A controller or use case validates the intent and calls the boundary. The boun...

Model routing and cascades for mobile AI

Not every request needs the largest model. This article turns that observation into a small implementation model you can test, measure, and keep boring when the app grows. The problem in one sentence Cheap first, escalate on uncertainty, measure quality. The useful question is not whether the API or pattern looks elegant in isolation. It is where state lives, which boundary owns failure, and how a user recovers when the happy path disappears. A practical model Classify difficulty; escalate only when confidence is low. Start with one explicit owner for the behavior. Keep widgets responsible for rendering and user intent; keep IO, persistence, permissions, and retries behind a small interface. That gives you a seam for a fake in tests and a place to record the facts that matter in production. For a Flutter app, the boundary usually looks like this: The widget emits an intent such as load, submit, refresh, or retry. A controller or use case validates the intent and calls the bou...

Unit economics of AI features in mobile apps — hướng dẫn Flutter

AI features can burn gross margin overnight. Bài này chuyển quan sát đó thành một mô hình nhỏ để bạn có thể kiểm thử, đo lường và giữ cho code dễ bảo trì khi app lớn lên. Vấn đề cốt lõi Cost per request, free tiers, and routing cheap models first. Câu hỏi hữu ích không phải API hay pattern có đẹp riêng lẻ hay không, mà là state nằm ở đâu, boundary nào chịu trách nhiệm khi lỗi xảy ra, và người dùng phục hồi thế nào khi happy path biến mất. Mô hình thực tế Route by task difficulty; cache aggressively. Hãy bắt đầu bằng một owner rõ ràng cho behavior. Widget chỉ nên render và phát intent; IO, persistence, permission và retry nên nằm sau một interface nhỏ. Nhờ vậy bạn có seam để fake trong test và một chỗ ghi lại các dữ kiện cần theo dõi ở production. Trong app Flutter, boundary thường có dạng: Widget phát intent như load, submit, refresh hoặc retry. Controller hoặc use case validate intent rồi gọi boundary. Boundary trả về data có kiểu hoặc failure có kiểu, không trả string chỉ ...

Unit economics of AI features in mobile apps

AI features can burn gross margin overnight. This article turns that observation into a small implementation model you can test, measure, and keep boring when the app grows. The problem in one sentence Cost per request, free tiers, and routing cheap models first. The useful question is not whether the API or pattern looks elegant in isolation. It is where state lives, which boundary owns failure, and how a user recovers when the happy path disappears. A practical model Route by task difficulty; cache aggressively. Start with one explicit owner for the behavior. Keep widgets responsible for rendering and user intent; keep IO, persistence, permissions, and retries behind a small interface. That gives you a seam for a fake in tests and a place to record the facts that matter in production. For a Flutter app, the boundary usually looks like this: The widget emits an intent such as load, submit, refresh, or retry. A controller or use case validates the intent and calls the boundar...

Unit economics of AI features in mobile apps — hướng dẫn Flutter

AI features can burn gross margin overnight. Bài này chuyển quan sát đó thành một mô hình nhỏ để bạn có thể kiểm thử, đo lường và giữ cho code dễ bảo trì khi app lớn lên. Vấn đề cốt lõi Cost per request, free tiers, and routing cheap models first. Câu hỏi hữu ích không phải API hay pattern có đẹp riêng lẻ hay không, mà là state nằm ở đâu, boundary nào chịu trách nhiệm khi lỗi xảy ra, và người dùng phục hồi thế nào khi happy path biến mất. Mô hình thực tế Route by task difficulty; cache aggressively. Hãy bắt đầu bằng một owner rõ ràng cho behavior. Widget chỉ nên render và phát intent; IO, persistence, permission và retry nên nằm sau một interface nhỏ. Nhờ vậy bạn có seam để fake trong test và một chỗ ghi lại các dữ kiện cần theo dõi ở production. Trong app Flutter, boundary thường có dạng: Widget phát intent như load, submit, refresh hoặc retry. Controller hoặc use case validate intent rồi gọi boundary. Boundary trả về data có kiểu hoặc failure có kiểu, không trả string chỉ ...

Định tuyến mô hình và thác bậc: chỉ trả tiền cho mức thông minh bạn cần

Hoá đơn về, và 90% trong đó là những yêu cầu kiểu “tóm tắt cái này trong một câu” hay “tin nhắn này có phải spam không?” — được gửi tới đúng cái model tiên tiến bạn dùng cho suy luận nhiều bước, chỉ vì đó là model bạn nối dây đầu tiên. Cách sửa nghe hiển nhiên: dùng model nhỏ ở chỗ model nhỏ là đủ . Cái khó nằm trọn trong chữ đủ , và trong việc biết yêu cầu nào là như vậy trước khi bạn có câu trả lời. Ba kiến trúc, không phải một Người ta nói “định tuyến” cho ba thứ khác nhau, và chúng có hồ sơ rủi ro khác nhau. Cách tiếp cận Quyết định thế nào Chi phí Rủi ro Định tuyến tĩnh Nhánh code quyết định model Ít phức tạp nhất Gán sai không lộ ra cho tới khi có phàn nàn chất lượng Định tuyến bằng phân loại Một model nhỏ hoặc heuristic chọn theo từng yêu cầu Thêm một lời gọi Phân loại sai đẩy việc khó cho model yếu Thác bậc Thử nhỏ trước, leo thang khi hỏng Đôi khi hai lời gọi đầy đủ Tiêu chí leo thang là toàn bộ bài toán Hãy bắt đầu bằng định tuyến tĩnh. Nó g...

Unit economics of AI features in mobile apps

AI features can burn gross margin overnight. This article turns that observation into a small implementation model you can test, measure, and keep boring when the app grows. The problem in one sentence Cost per request, free tiers, and routing cheap models first. The useful question is not whether the API or pattern looks elegant in isolation. It is where state lives, which boundary owns failure, and how a user recovers when the happy path disappears. A practical model Route by task difficulty; cache aggressively. Start with one explicit owner for the behavior. Keep widgets responsible for rendering and user intent; keep IO, persistence, permissions, and retries behind a small interface. That gives you a seam for a fake in tests and a place to record the facts that matter in production. For a Flutter app, the boundary usually looks like this: The widget emits an intent such as load, submit, refresh, or retry. A controller or use case validates the intent and calls the boundar...

Định tuyến mô hình và thác bậc: chỉ trả tiền cho mức thông minh bạn cần

Hoá đơn về, và 90% trong đó là những yêu cầu kiểu “tóm tắt cái này trong một câu” hay “tin nhắn này có phải spam không?” — được gửi tới đúng cái model tiên tiến bạn dùng cho suy luận nhiều bước, chỉ vì đó là model bạn nối dây đầu tiên. Cách sửa nghe hiển nhiên: dùng model nhỏ ở chỗ model nhỏ là đủ . Cái khó nằm trọn trong chữ đủ , và trong việc biết yêu cầu nào là như vậy trước khi bạn có câu trả lời. Ba kiến trúc, không phải một Người ta nói “định tuyến” cho ba thứ khác nhau, và chúng có hồ sơ rủi ro khác nhau. Cách tiếp cận Quyết định thế nào Chi phí Rủi ro Định tuyến tĩnh Nhánh code quyết định model Ít phức tạp nhất Gán sai không lộ ra cho tới khi có phàn nàn chất lượng Định tuyến bằng phân loại Một model nhỏ hoặc heuristic chọn theo từng yêu cầu Thêm một lời gọi Phân loại sai đẩy việc khó cho model yếu Thác bậc Thử nhỏ trước, leo thang khi hỏng Đôi khi hai lời gọi đầy đủ Tiêu chí leo thang là toàn bộ bài toán Hãy bắt đầu bằng định tuyến tĩnh. Nó g...

Model routing and cascades: paying for the intelligence you need

Your bill arrives and 90% of it is requests like “summarise this in one sentence” and “is this message spam?” — sent to the same frontier model you use for multi-step reasoning, because that was the one you wired up first. The fix is obvious in principle: use a smaller model where a smaller model suffices. The difficulty is entirely in the word suffices , and in knowing which requests those are before you have the answer. Three architectures, not one People say “routing” for three different things, and they have different risk profiles. Approach How it decides Cost Risk Static routing The code path determines the model Lowest complexity Wrong assignment is invisible until quality complaints Classifier routing A small model or heuristic picks per request One extra call Misclassification sends hard work to a weak model Cascade Try small, escalate on failure Sometimes two full calls Escalation criteria are the whole problem Start with static routing. It ...

Model routing and cascades: paying for the intelligence you need

Your bill arrives and 90% of it is requests like “summarise this in one sentence” and “is this message spam?” — sent to the same frontier model you use for multi-step reasoning, because that was the one you wired up first. The fix is obvious in principle: use a smaller model where a smaller model suffices. The difficulty is entirely in the word suffices , and in knowing which requests those are before you have the answer. Three architectures, not one People say “routing” for three different things, and they have different risk profiles. Approach How it decides Cost Risk Static routing The code path determines the model Lowest complexity Wrong assignment is invisible until quality complaints Classifier routing A small model or heuristic picks per request One extra call Misclassification sends hard work to a weak model Cascade Try small, escalate on failure Sometimes two full calls Escalation criteria are the whole problem Start with static routing. It ...