# How to post data to dynamic batch directly？

**URL:** <https://discuss.ray.io/t/how-to-post-data-to-dynamic-batch-directly/16060>\
**Category:** Ray Serve\
**Created:** [October 23, 2024, 8:46am UTC](https://discuss.ray.io/t/how-to-post-data-to-dynamic-batch-directly/16060 "2024-10-23T08:46:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hspix](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/hspix/32/6663_2.png) [@Hspix](https://discuss.ray.io/u/Hspix)\
**Post date:** [October 23, 2024, 8:46am UTC](https://discuss.ray.io/t/how-to-post-data-to-dynamic-batch-directly/16060/1 "2024-10-23T08:46:49Z")

</div>

- High: It blocks me to complete my task.

Example from [ray serve document](https://docs.ray.io/en/latest/serve/advanced-guides/dyn-req-batch.html?_gl=1*1ex3cbc*_up*MQ..*_ga*MTE5NzYwNTk3Mi4xNzI5NjY1NDgy*_ga_0LCWHW1N3S*MTcyOTY2NTQ4Mi4xLjEuMTcyOTY2NjkwNy4wLjAuMA..),

```auto
from typing import List

import numpy as np

from ray import serve
from ray.serve.handle import DeploymentHandle

@serve.deployment
class Model:
    @serve.batch(max_batch_size=8, batch_wait_timeout_s=0.1)
    async def __call__ (self, multiple_samples: List[int]) -> List[int]:
        # Use numpy's vectorized computation to efficiently process a batch.
        return np.array(multiple_samples) * 2

```

How can I use `requests.post` to invoke ` __call__ ` directly？

---

<div class="post-metadata">

**Author:** ![cindy\_zhang](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/cindy_zhang/32/3559_2.png) [@cindy\_zhang](https://discuss.ray.io/u/cindy_zhang)\
**Post date:** [October 24, 2024, 4:04pm UTC](https://discuss.ray.io/t/how-to-post-data-to-dynamic-batch-directly/16060/2 "2024-10-24T16:04:49Z")

</div>

Hi @Hspix, if you use the `Model` you defined and run it with `serve.run`, you’ll be able to hit ` __call__ ` with `requests.post`:

```auto
@serve.deployment
class Model:
    @serve.batch(max_batch_size=8, batch_wait_timeout_s=0.1)
    async def __call__ (self, multiple_samples: List[int]) -> List[int]:
        # Use numpy's vectorized computation to efficiently process a batch.
        return np.array(multiple_samples) * 2

serve.run(Model.bind())
r = requests.post("http://localhost:8000")

```

The `multiple_samples` argument in your ` __call__ ` function will be a list of `starlette.requests.Request` objects, not a list of integers.
