Skip to content

Roboflow api

post_to_roboflow_api(endpoint, api_key, payload=None, params=None)

Generic function to make a POST request to the Roboflow API.

Source code in inference/core/roboflow_api.py
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
@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()