@@ -253,17 +253,24 @@ def __init__(
253253 project_id : Optional [str ] = None ,
254254 base_url : str = "https://tracing.fireworks.ai" ,
255255 timeout : int = 300 ,
256+ api_key : Optional [str ] = None ,
256257 ):
257258 """Initialize the Fireworks Tracing adapter.
258259
259260 Args:
260261 project_id: Optional project ID. If not provided, uses the default project configured on the server.
261262 base_url: The base URL of the tracing proxy (default: https://tracing.fireworks.ai)
262263 timeout: Request timeout in seconds (default: 300)
264+ api_key: Optional API key. If not provided, falls back to FIREWORKS_API_KEY environment variable.
263265 """
264266 self .project_id = project_id
265267 self .base_url = base_url .rstrip ("/" )
266268 self .timeout = timeout
269+ self ._api_key = api_key
270+
271+ def _get_api_key (self ) -> Optional [str ]:
272+ """Get the API key, preferring instance-level key over environment variable."""
273+ return self ._api_key or os .environ .get ("FIREWORKS_API_KEY" )
267274
268275 def search_logs (self , tags : List [str ], limit : int = 100 , hours_back : int = 24 ) -> List [Dict [str , Any ]]:
269276 """Fetch logs from Fireworks tracing gateway /logs endpoint.
@@ -276,7 +283,7 @@ def search_logs(self, tags: List[str], limit: int = 100, hours_back: int = 24) -
276283 from ..common_utils import get_user_agent
277284
278285 headers = {
279- "Authorization" : f"Bearer { os . environ . get ( 'FIREWORKS_API_KEY' )} " ,
286+ "Authorization" : f"Bearer { self . _get_api_key ( )} " ,
280287 "User-Agent" : get_user_agent (),
281288 }
282289 params : Dict [str , Any ] = {"tags" : tags , "limit" : limit , "hours_back" : hours_back , "program" : "eval_protocol" }
@@ -407,7 +414,7 @@ def get_evaluation_rows(
407414 from ..common_utils import get_user_agent
408415
409416 headers = {
410- "Authorization" : f"Bearer { os . environ . get ( 'FIREWORKS_API_KEY' )} " ,
417+ "Authorization" : f"Bearer { self . _get_api_key ( )} " ,
411418 "User-Agent" : get_user_agent (),
412419 }
413420
0 commit comments