Skip to content

Add eval-protocol user-agent to fireworks api requests#311

Merged
dphuang2 merged 11 commits intomainfrom
cursor/add-eval-protocol-user-agent-to-fireworks-api-requests-8a45
Nov 4, 2025
Merged

Add eval-protocol user-agent to fireworks api requests#311
dphuang2 merged 11 commits intomainfrom
cursor/add-eval-protocol-user-agent-to-fireworks-api-requests-8a45

Conversation

@dphuang2
Copy link
Copy Markdown
Collaborator

@dphuang2 dphuang2 commented Nov 3, 2025

This pull request contains changes generated by a Cursor Cloud Agent

Open in Cursor Open in Web


Note

Adds a centralized get_user_agent() and sets User-Agent on Fireworks API/tracing requests across the codebase, with minor URL/header refactors.

  • Common utils:
    • Add get_user_agent() returning eval-protocol/{version}.
  • HTTP calls updated with User-Agent:
    • auth.verify_api_key_and_get_account_id()
    • Tracing adapter: search_logs() and get_evaluation_rows() in adapters/fireworks_tracing.py.
    • Evaluator: preview and create endpoints in evaluation.py.
    • RFT utilities: dataset create/upload and RFT job create in fireworks_rft.py.
    • Generation client: Fireworks chat completions in generation/clients.py.
    • Platform secrets API: get/create/update/delete in platform_api.py.
    • Pytest persist flow: dataset create/upload and eval job create in pytest/handle_persist_flow.py.
  • Minor refactors:
    • Centralize api_base/url construction and reuse header objects in several functions.

Written by Cursor Bugbot for commit 4528c55. This will update automatically on new commits. Configure here.

Co-authored-by: dhuang <dhuang@fireworks.ai>
@cursor
Copy link
Copy Markdown

cursor bot commented Nov 3, 2025

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {api_key}" if api_key else "",
"User-Agent": get_user_agent(),
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cursor no need here

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taking a look!

Open in Cursor Open in Web

Co-authored-by: dhuang <dhuang@fireworks.ai>
Comment on lines +27 to +30
self._session.headers.update({
"Authorization": f"Bearer {api_key}",
"User-Agent": get_user_agent(),
})
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cursor no need for tracing.fireworks.ai calls

Copy link
Copy Markdown

@cursor cursor bot Nov 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! I've removed the user-agent header from reward_function.py. The user-agent will now only be added to direct Fireworks API requests from the CLI, not to reward function endpoint calls.


Open in Cursor Open in Web

Learn more about Cursor Agents

Copy link
Copy Markdown
Collaborator Author

@dphuang2 dphuang2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cursor can we DRY the code as much as possible so calls to api.fireworks.ai go through a client that always has the headers?

Co-authored-by: dhuang <dhuang@fireworks.ai>
@dphuang2
Copy link
Copy Markdown
Collaborator Author

dphuang2 commented Nov 3, 2025

@cursor can we DRY the code as much as possible so calls to api.fireworks.ai go through a client that always has the headers?

@cursor
Copy link
Copy Markdown

cursor bot commented Nov 3, 2025

Excellent! The refactoring is complete. Let me create a summary:

Summary

I've successfully refactored the code to follow DRY principles by creating a centralized FireworksAPIClient that handles all requests to api.fireworks.ai with consistent headers.

What was done:

  1. Created FireworksAPIClient (fireworks_api_client.py):

    • Centralized client class that automatically includes:
      • User-Agent: eval-protocol-cli/{version} header
      • Authorization: Bearer {api_key} header
      • Proper Content-Type handling
    • Supports all HTTP methods (GET, POST, PUT, PATCH, DELETE)
    • Handles file uploads properly
    • Uses a requests Session for connection pooling
  2. Refactored 6 files to use the new client:

    • auth.py - API key verification
    • fireworks_rft.py - Dataset creation/upload, RFT job creation
    • platform_api.py - Secret management (create, get, delete)
    • evaluation.py - Evaluator preview and deployment
    • pytest/handle_persist_flow.py - Dataset upload from pytest
  3. Kept as-is:

    • generation/clients.py - Uses aiohttp (async), still includes user-agent manually
    • adapters/fireworks_tracing.py - No user-agent (tracing.fireworks.ai calls)
    • log_utils/fireworks_tracing_http_handler.py - No user-agent (tracing.fireworks.ai calls)
    • reward_function.py - No user-agent (not needed for reward function endpoints)

The code is now much more maintainable with all Fireworks API requests going through a single client that ensures consistent headers across the codebase!


Open in Cursor Open in Web

Learn more about Cursor Agents

This change centralizes API request logic into a new FireworksAPIClient class, simplifying
and standardizing how the Fireworks API is interacted with across the project.
It removes redundant request setup code and ensures consistent headers are sent.

Co-authored-by: dhuang <dhuang@fireworks.ai>
@dphuang2 dphuang2 marked this pull request as ready for review November 3, 2025 22:34
cursor[bot]

This comment was marked as outdated.

url = f"{resolved_api_base.rstrip('/')}/v1/accounts/{resolved_account_id}/secrets/{resource_id}"

try:
url = f"{resolved_api_base}/v1/accounts/{resolved_account_id}/secrets/{resource_id}"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Malformed URLs from trailing slash removal.

Removing .rstrip('/') from URL construction in platform_api.py can create malformed URLs with double slashes when resolved_api_base includes a trailing slash. This might cause HTTP request failures and is inconsistent with URL handling in other files.

Fix in Cursor Fix in Web

@dphuang2 dphuang2 merged commit 5e76d33 into main Nov 4, 2025
9 checks passed
@dphuang2 dphuang2 deleted the cursor/add-eval-protocol-user-agent-to-fireworks-api-requests-8a45 branch November 4, 2025 00:54
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.

3 participants