Skip to content

Ability to set maxTokens when calling prompt() #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
duci9y opened this issue Aug 29, 2024 · 2 comments
Open

Ability to set maxTokens when calling prompt() #36

duci9y opened this issue Aug 29, 2024 · 2 comments
Labels
ecosystem parity A feature that other popular language model APIs offer enhancement New feature or request

Comments

@duci9y
Copy link

duci9y commented Aug 29, 2024

I'd like to be able to constrain the output to N tokens for my use case (tab autocompletion). Otherwise the model generates strings that are too long to be useful. It also takes more time.

@etiennenoel
Copy link

Do you have a use case for N tokens or number of words? I am tempted to think that developers will probably want a number of words and if that's the case,

@domenic Should we ask devs to do this using Regex with Structured Output?

@domenic
Copy link
Collaborator

domenic commented May 28, 2025

Although I agree there is some overlap with response constraints, I think there's sufficient precedent in server-side APIs for exactly this constraint such that we might want to include it. Additionally, we already expose token limits in the API (via inputUsage / inputQuota).

It's possible most people using this on server-side APIs are concerned about costs, which are not as applicable for built-in AI. But here we have at least one user suggesting it's about usefulness and time taken.

What I can't easily find out from public docs is how this is implemented in existing server-side APIs. Does it get piped to the model, so that the model tries to stay within the limit? Or is it just a hard cutoff on the frontend, whenever the limit is reached?

Some experimentation in the OpenAI playground implies it's the latter:

Image

@domenic domenic added the ecosystem parity A feature that other popular language model APIs offer label Jun 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ecosystem parity A feature that other popular language model APIs offer enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants