Skip to content

Conversation

@Feel-ix-343
Copy link
Contributor

@Feel-ix-343 Feel-ix-343 commented Nov 25, 2025

Add cost_dollars field to AnswerResponse and StreamAnswerResponse

Summary

Fixes #134 - The API returns costDollars in answer responses, but the SDK was not exposing this field.

This PR adds the cost_dollars field to:

  • AnswerResponse dataclass
  • StreamChunk dataclass (for streaming responses)

The implementation follows the existing pattern used by SearchResponse for handling cost_dollars, reusing the existing parse_cost_dollars() helper function.

Review & Testing Checklist for Human

  • Verify API response structure: Confirm that the /answer endpoint actually returns costDollars with the expected structure (total, search, contents breakdown). The CostDollars type was designed for search responses - verify it matches answer responses.
  • Test streaming responses: Verify that costDollars is included in streaming chunks (typically the final chunk). I couldn't test this against the live API.
  • Test with live API: Run a simple test like:
    from exa_py import Exa
    exa = Exa(api_key="...")
    response = exa.answer("What is Python?")
    print(response.cost_dollars)  # Should show cost breakdown

Notes

…erResponse

Fixes #134 - AnswerResponse and StreamAnswerResponse were missing the
cost_dollars field that the API returns.

Changes:
- Added cost_dollars field to AnswerResponse dataclass
- Added cost_dollars field to StreamChunk dataclass
- Updated Exa.answer() and AsyncExa.answer() to parse costDollars from response
- Updated StreamAnswerResponse and AsyncStreamAnswerResponse to parse
  costDollars from streaming chunks
- Updated __str__ methods to include cost_dollars in output

Co-Authored-By: Felix Zeller <felixazeller@gmail.com>
@devin-ai-integration
Copy link
Contributor

Original prompt from Felix
fix this https://github.com/exa-labs/exa-py/issues/134

@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR that start with 'DevinAI' or '@devin'.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

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.

AnswerResponse missing cost_dollars field

2 participants