Count input tokens

Count the tokens in the fully rendered input for a Responses request, without generating or storing a response. The count includes resolved previous_response_id history, current instructions and tools, media, and server-injected prompt scaffolding. Conversation resources are not supported.

POST /responses/input_tokens

Count tokens in the fully rendered input for a Responses request without generating or storing a response.

Request body

Content Type: application/json

CreateResponse

Response

HTTP 200 — Success

Content Type: application/json

TokenCountsResource

python
import json
import os
import requests
response = requests.post(
"https://api.meta.ai/v1/responses/input_tokens",
headers={
"Authorization": f"Bearer {os.environ['MODEL_API_KEY']}",
"Content-Type": "application/json",
},
json={
"model": "muse-spark-1.3",
"input": "What is the capital of France?",
},
)
response.raise_for_status()
print(json.dumps(response.json(), indent=2))

For usage examples and rate-limit guidance, see the Responses feature page.