Skip to content
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

Why is usage optional? #746

Closed
MatanYadaev opened this issue Apr 1, 2024 · 4 comments
Closed

Why is usage optional? #746

MatanYadaev opened this issue Apr 1, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@MatanYadaev
Copy link

MatanYadaev commented Apr 1, 2024

Describe the bug

/**
* Usage statistics for the completion request.
*/
usage?: CompletionsAPI.CompletionUsage;

To Reproduce

const chatCompletion = new OpenAI({ ... }).chat.completion.create({ ... })

const totalTokens = chatCompletion.usage.total_tokens; // TS18048: `chatCompletion.usage` is possibly `undefined` 

Code snippets

Library version

v4.31.0

@MatanYadaev MatanYadaev added the bug Something isn't working label Apr 1, 2024
@MatanYadaev MatanYadaev changed the title Why usage is optional? Why is usage optional? Apr 1, 2024
@rattrayalex
Copy link
Collaborator

When streaming, this is not supplied from the server currently.

@rattrayalex rattrayalex closed this as not planned Won't fix, can't repro, duplicate, stale Apr 1, 2024
@MatanYadaev
Copy link
Author

MatanYadaev commented Apr 1, 2024

@rattrayalex Worth mentioning that in the JSDoc of this property. I thought it's optional only when streaming, but wasn't sure if in the other cases, it will 100% be present.

@rattrayalex
Copy link
Collaborator

That's a good point, I'll bump that to the relevant team (this would flow through from the OpenAPI spec).

@rattrayalex
Copy link
Collaborator

Related: #506

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants