https://www.boundaryml.com logo
Set max output tokens for the `output_format` sche...
# help
j
I am wondering if its possible set the max output tokens for the output schema? When I do this:
Copy code
client<llm> Imagen4JSON {
  provider "openai-generic"
  retry_policy Exponential
  options {
    base_url "https://openrouter.ai/api/v1"
    api_key env.OPENROUTER_API_KEY
    model "google/gemini-2.5-flash"
    max_tokens 480  /
That's not quite what I want as there may be chain of thought etc before, but the final output schema i'd like a certain number of tokens.
v
we sadly only support the API interface that the model provider exposes 🙁
but i can see why you might want an error if the schema is too large
kind of like a linter
its an interesting idea
how do you think about this when models use different tokenizers?
j
ya, basically my use case is generating prompts that will be used to feed into imagen4 which has a input limit of 480 tokens So what I was thinking would be cool is my baml response schema is like * title * emoji * prompt (limit to 480) (I was using json schema for this) I guess what I can do is break it up so just generate a natural language prompt with no chain of thought before
v
hmm the idea that a developer wants to contrain sections of the prompt to a limited numbers of tokens is interesting the more i think about it...
j
it might be pretty niche, I only am now facing this as I was using nano banana before, but I switched to imagen4 which has this quite small limit. I think i'll be able to find something that works, but thought i'd see if you guys had a way 🙂
v
what you can do is: 1. use modular api to analyze the prompt + check for length? 2. then call regular BAML function
though i really hate that DX 🙁
j
ah interesting, havn't looked at modular api. i'll take a look, thanks! I already have something working pretty good with baml and imagen4 before I even noticed this limit. But I noticed the odd time the images not coming out great, and I think its because sometimes the prompt is coming out too long so context is getting ignored. Doesn't seem very frequent but thought if I could control that then I could ignore that issue