-
Notifications
You must be signed in to change notification settings - Fork 16
Add eval-protocol user-agent to fireworks api requests #311
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
Merged
dphuang2
merged 11 commits into
main
from
cursor/add-eval-protocol-user-agent-to-fireworks-api-requests-8a45
Nov 4, 2025
Merged
Changes from 4 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a1e8fed
Add User-Agent header to Fireworks API requests
cursoragent cbc418b
Remove unused User-Agent header from RewardFunction
cursoragent 00339e8
Remove unnecessary User-Agent header from Fireworks adapter
cursoragent d406ce0
Refactor: Use FireworksAPIClient for all API requests
cursoragent 0ba3df5
fix lint errors
ff67aff
fix lint errors
1b10a8f
Update User-Agent format in get_user_agent function to use 'eval-prot…
1a14b73
added tests
432021a
update
04a2a2f
reject absolute within path arg
4528c55
revert
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| """Centralized client for making requests to Fireworks API with consistent headers.""" | ||
|
|
||
| import os | ||
| from typing import Any, Dict, Optional | ||
|
|
||
| import requests | ||
|
|
||
| from .common_utils import get_user_agent | ||
|
|
||
|
|
||
| class FireworksAPIClient: | ||
| """Client for making authenticated requests to Fireworks API with proper headers. | ||
|
|
||
| This client automatically includes: | ||
| - Authorization header (Bearer token) | ||
| - User-Agent header for tracking eval-protocol CLI usage | ||
| """ | ||
|
|
||
| def __init__(self, api_key: Optional[str] = None, api_base: Optional[str] = None): | ||
| """Initialize the Fireworks API client. | ||
|
|
||
| Args: | ||
| api_key: Fireworks API key. If None, will be read from environment. | ||
| api_base: API base URL. If None, defaults to https://api.fireworks.ai | ||
| """ | ||
| self.api_key = api_key | ||
| self.api_base = api_base or os.environ.get("FIREWORKS_API_BASE", "https://api.fireworks.ai") | ||
| self._session = requests.Session() | ||
|
|
||
| def _get_headers(self, content_type: Optional[str] = "application/json", | ||
| additional_headers: Optional[Dict[str, str]] = None) -> Dict[str, str]: | ||
| """Build headers for API requests. | ||
|
|
||
| Args: | ||
| content_type: Content-Type header value. If None, Content-Type won't be set. | ||
| additional_headers: Additional headers to merge in. | ||
|
|
||
| Returns: | ||
| Dictionary of headers including authorization and user-agent. | ||
| """ | ||
| headers = { | ||
| "User-Agent": get_user_agent(), | ||
| } | ||
|
|
||
| if self.api_key: | ||
| headers["Authorization"] = f"Bearer {self.api_key}" | ||
|
|
||
| if content_type: | ||
| headers["Content-Type"] = content_type | ||
|
|
||
| if additional_headers: | ||
| headers.update(additional_headers) | ||
|
|
||
| return headers | ||
|
|
||
| def get(self, path: str, params: Optional[Dict[str, Any]] = None, | ||
| timeout: int = 30, **kwargs) -> requests.Response: | ||
| """Make a GET request to the Fireworks API. | ||
|
|
||
| Args: | ||
| path: API path (relative to api_base) | ||
| params: Query parameters | ||
| timeout: Request timeout in seconds | ||
| **kwargs: Additional arguments passed to requests.get | ||
|
|
||
| Returns: | ||
| Response object | ||
| """ | ||
| url = f"{self.api_base.rstrip('/')}/{path.lstrip('/')}" | ||
| headers = self._get_headers(content_type=None) | ||
| if "headers" in kwargs: | ||
| headers.update(kwargs.pop("headers")) | ||
| return self._session.get(url, params=params, headers=headers, timeout=timeout, **kwargs) | ||
|
|
||
| def post(self, path: str, json: Optional[Dict[str, Any]] = None, | ||
| data: Optional[Any] = None, files: Optional[Dict[str, Any]] = None, | ||
| timeout: int = 60, **kwargs) -> requests.Response: | ||
| """Make a POST request to the Fireworks API. | ||
|
|
||
| Args: | ||
| path: API path (relative to api_base) | ||
| json: JSON payload | ||
| data: Form data payload | ||
| files: Files to upload | ||
| timeout: Request timeout in seconds | ||
| **kwargs: Additional arguments passed to requests.post | ||
|
|
||
| Returns: | ||
| Response object | ||
| """ | ||
| url = f"{self.api_base.rstrip('/')}/{path.lstrip('/')}" | ||
|
|
||
| # For file uploads, don't set Content-Type (let requests handle multipart/form-data) | ||
| content_type = None if files else "application/json" | ||
| headers = self._get_headers(content_type=content_type) | ||
|
|
||
| if "headers" in kwargs: | ||
| headers.update(kwargs.pop("headers")) | ||
|
|
||
| return self._session.post(url, json=json, data=data, files=files, | ||
| headers=headers, timeout=timeout, **kwargs) | ||
|
|
||
| def put(self, path: str, json: Optional[Dict[str, Any]] = None, | ||
| timeout: int = 60, **kwargs) -> requests.Response: | ||
| """Make a PUT request to the Fireworks API.""" | ||
| url = f"{self.api_base.rstrip('/')}/{path.lstrip('/')}" | ||
| headers = self._get_headers() | ||
| if "headers" in kwargs: | ||
| headers.update(kwargs.pop("headers")) | ||
| return self._session.put(url, json=json, headers=headers, timeout=timeout, **kwargs) | ||
|
|
||
| def patch(self, path: str, json: Optional[Dict[str, Any]] = None, | ||
| timeout: int = 60, **kwargs) -> requests.Response: | ||
| """Make a PATCH request to the Fireworks API.""" | ||
| url = f"{self.api_base.rstrip('/')}/{path.lstrip('/')}" | ||
| headers = self._get_headers() | ||
| if "headers" in kwargs: | ||
| headers.update(kwargs.pop("headers")) | ||
| return self._session.patch(url, json=json, headers=headers, timeout=timeout, **kwargs) | ||
|
|
||
| def delete(self, path: str, timeout: int = 30, **kwargs) -> requests.Response: | ||
| """Make a DELETE request to the Fireworks API.""" | ||
| url = f"{self.api_base.rstrip('/')}/{path.lstrip('/')}" | ||
| headers = self._get_headers(content_type=None) | ||
| if "headers" in kwargs: | ||
| headers.update(kwargs.pop("headers")) | ||
| return self._session.delete(url, headers=headers, timeout=timeout, **kwargs) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Malformed URLs from incorrect path handling in API calls
The
FireworksAPIClient.post()method expects a relative path, but the code passes full URLs forgetUploadEndpointandvalidateUploadcalls. This leads to malformed URLs (e.g.,api_base/api_base/path) and causes these API requests to fail.