Skip to main content


Exposes API that can be used for the Web API testing. This class is used for creating APIRequestContext instance which in turn can be used for sending web requests. An instance of this class can be obtained via playwright.request. For more information see APIRequestContext.


Added in: v1.16
  • base_url <str> Methods like api_request_context.get(url, **kwargs) take the base URL into consideration by using the URL() constructor for building the corresponding URL. Examples:#
    • baseURL: http://localhost:3000 and sending request to /bar.html results in http://localhost:3000/bar.html
    • baseURL: http://localhost:3000/foo/ and sending request to ./bar.html results in http://localhost:3000/foo/bar.html
    • baseURL: http://localhost:3000/foo (without trailing slash) and navigating to ./bar.html results in http://localhost:3000/bar.html
  • extra_http_headers <Dict[str, str]> An object containing additional HTTP headers to be sent with every request.#
  • http_credentials <Dict> Credentials for HTTP authentication.#
  • ignore_https_errors <bool> Whether to ignore HTTPS errors when sending network requests. Defaults to false.#
  • proxy <Dict> Network proxy settings.#
    • server <str> Proxy to be used for all requests. HTTP and SOCKS proxies are supported, for example or socks5:// Short form is considered an HTTP proxy.
    • bypass <str> Optional comma-separated domains to bypass proxy, for example ".com,,".
    • username <str> Optional username to use if HTTP proxy requires authentication.
    • password <str> Optional password to use if HTTP proxy requires authentication.
  • storage_state <Union[str, pathlib.Path]|Dict> Populates context with given storage state. This option can be used to initialize context with logged-in information obtained via browser_context.storage_state(**kwargs) or api_request_context.storage_state(**kwargs). Either a path to the file with saved storage, or the value returned by one of browser_context.storage_state(**kwargs) or api_request_context.storage_state(**kwargs) methods.#
  • timeout <float> Maximum time in milliseconds to wait for the response. Defaults to 30000 (30 seconds). Pass 0 to disable timeout.#
  • user_agent <str> Specific user agent to use in this context.#
  • returns: <APIRequestContext>#

Creates new instances of APIRequestContext.