Generic function to make a POST request to the Roboflow API.
Source code in inference/core/roboflow_api.py
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836 | @wrap_roboflow_api_errors()
def post_to_roboflow_api(
endpoint: str,
api_key: Optional[str],
payload: Optional[dict] = None,
params: Optional[List[Tuple[str, str]]] = None,
) -> dict:
"""Generic function to make a POST request to the Roboflow API."""
url_params = []
if api_key:
url_params.append(("api_key", api_key))
if params:
url_params.extend(params)
full_url = _add_params_to_url(
url=f"{API_BASE_URL}/{endpoint.strip('/')}", params=url_params
)
wrapped_url = wrap_url(full_url)
headers = build_roboflow_api_headers()
response = requests.post(
url=wrapped_url,
json=payload,
headers=headers,
timeout=ROBOFLOW_API_REQUEST_TIMEOUT,
)
api_key_safe_raise_for_status(response=response)
return response.json()
|