MCPcopy Create free account
hub / github.com/OpenPipe/OpenPipe / OpenPipeApi

Class OpenPipeApi

client-libs/python/openpipe/api_client/client.py:45–393  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

43
44
45class OpenPipeApi:
46 def __init__(
47 self,
48 *,
49 base_url: typing.Optional[str] = None,
50 environment: OpenPipeApiEnvironment = OpenPipeApiEnvironment.DEFAULT,
51 token: typing.Union[str, typing.Callable[[], str]],
52 timeout: typing.Optional[float] = 240,
53 httpx_client: typing.Optional[httpx.Client] = None,
54 ):
55 self._client_wrapper = SyncClientWrapper(
56 base_url=_get_base_url(base_url=base_url, environment=environment),
57 token=token,
58 httpx_client=httpx.Client(timeout=timeout) if httpx_client is None else httpx_client,
59 )
60
61 def check_cache(
62 self,
63 *,
64 requested_at: float,
65 req_payload: typing.Optional[typing.Any] = OMIT,
66 tags: typing.Optional[typing.Dict[str, str]] = OMIT,
67 ) -> CheckCacheResponse:
68 """
69 DEPRECATED: we no longer support prompt caching.
70
71 Parameters:
72 - requested_at: float. Unix timestamp in milliseconds
73
74 - req_payload: typing.Optional[typing.Any].
75
76 - tags: typing.Optional[typing.Dict[str, str]]. Extra tags to attach to the call for filtering. Eg { "userId": "123", "promptId": "populate-title" }
77 """
78 _request: typing.Dict[str, typing.Any] = {"requestedAt": requested_at}
79 if req_payload is not OMIT:
80 _request["reqPayload"] = req_payload
81 if tags is not OMIT:
82 _request["tags"] = tags
83 _response = self._client_wrapper.httpx_client.request(
84 "POST",
85 urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "check-cache"),
86 json=jsonable_encoder(_request),
87 headers=self._client_wrapper.get_headers(),
88 timeout=240,
89 )
90 if 200 <= _response.status_code < 300:
91 return pydantic.parse_obj_as(CheckCacheResponse, _response.json()) # type: ignore
92 try:
93 _response_json = _response.json()
94 except JSONDecodeError:
95 raise ApiError(status_code=_response.status_code, body=_response.text)
96 raise ApiError(status_code=_response.status_code, body=_response_json)
97
98 def create_chat_completion(
99 self,
100 *,
101 req_payload: typing.Optional[CreateChatCompletionRequestReqPayload] = OMIT,
102 model: typing.Optional[str] = OMIT,

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected