Skip to content

feat(OpenAI): add the input token count endpoint of the Responses API - #844

Open
skybleak333 wants to merge 1 commit into
openai-php:mainfrom
skybleak333:feat/responses-input-tokens
Open

skybleak333 wants to merge 1 commit into
openai-php:mainfrom
skybleak333:feat/responses-input-tokens

Conversation

@skybleak333

Copy link
Copy Markdown
Contributor

What:

  • Bug Fix
  • New Feature

Description:

Adds POST /v1/responses/input_tokens, which counts the input tokens of a request without creating a response. It takes the same parameters as responses()->create() and answers with {"object": "response.input_tokens", "input_tokens": 11} (token counting guide). Useful to check a long conversation against the context window, or to estimate the cost, before sending it.

$response = $client->responses()->inputTokens()->count([
    'model' => 'gpt-5',
    'input' => 'Tell me a joke.',
]);

$response->inputTokens; // 11

The naming follows the official SDKs (client.responses.input_tokens.count() in Python, client.responses.inputTokens.count() in Node) and the conversations()->items() sub-resource here: ResponsesInputTokens with its contract, InputTokenCountResponse with a fake fixture, ResponsesInputTokensTestResource for ClientFake, and a README section. The full suite, Pint and PHPStan pass.

@iBotPeaches

Copy link
Copy Markdown
Collaborator

Never used this. Will test it for real and report back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants