# Openai python SDK Lambda Issues

**URL:** <https://community.openai.com/t/openai-python-sdk-lambda-issues/619625>\
**Category:** API\
**Created:** [February 9, 2024, 12:22am UTC](https://community.openai.com/t/openai-python-sdk-lambda-issues/619625 "2024-02-09T00:22:32Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![luke11](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/luke11/32/302845_2.png) [@luke11](https://community.openai.com/u/luke11)\
**Post date:** [February 9, 2024, 12:22am UTC](https://community.openai.com/t/openai-python-sdk-lambda-issues/619625/1 "2024-02-09T00:22:32Z")

</div>

I have been trying to get the openai python package in to my Lambda function. I keep running in to the error

```auto
Runtime.ImportModuleError: Unable to import module 'serverless_aws_lambda_sdk.internal_extension.wrapper': No module named 'pydantic_core._pydantic_core'

```

I have tried using Docker to make sure I am pip-ing the correct architecture both x86 and arm64 (while also changing my lambda arch). I am using the Serverless framework, along with a layer. From what I have found elsewhere it seems that using a Docker image should fix it, so maybe I am running into issues and not setting up my Docker correctly. I have tried using the pre-built layers found on GitHub (I can’t post a link), and this hasn’t worked either.

Has anyone found a good solution to trying to get openai package into Lambda?

---

<div class="post-metadata">

**Author:** ![renanpolonio](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/renanpolonio/32/299762_2.png) [@renanpolonio](https://community.openai.com/u/renanpolonio)\
**Post date:** [February 10, 2024, 2:59pm UTC](https://community.openai.com/t/openai-python-sdk-lambda-issues/619625/2 "2024-02-10T14:59:58Z")

</div>

> [@luke11](#):
>
> using Docker to make

After a while I figureout how to solve this. At least for my specific project. What I did was:  
Create a python folder and install the following:

- pip install -t ./python fastapi==0.99.0 openai
- Create a python layer using python 3.11 version, upload this python folder and select x86 and arm64 compatibility.
- I also needed requests in my project, so I also did  
pip install --target ./packages requests==2.29.0
- I upload my lambda function with the requests 2.29.0 libraries installed in my packages folder in the root level

Use the python layer you created in your lambda and it should work.

---

<div class="post-metadata">

**Author:** ![dpickut2](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/dpickut2/32/512159_2.png) [@dpickut2](https://community.openai.com/u/dpickut2)\
**Post date:** [February 10, 2024, 8:22pm UTC](https://community.openai.com/t/openai-python-sdk-lambda-issues/619625/3 "2024-02-10T20:22:55Z")

</div>

I was able to use pip to install the openai packages on my x86 Mac following the guidance in this AWS article: [Working with .zip file archives for Python Lambda functions - AWS Lambda](https://docs.aws.amazon.com/lambda/latest/dg/python-package.html#python-package-native-libraries)

I then zipped it and oploaded it to an AWS layer. The pip install parameters are critical to get the correct wheel files that are compatible with Lambda.

---

<div class="post-metadata">

**Author:** ![curt.kennedy](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/curt.kennedy/32/709249_2.png) [@curt.kennedy](https://community.openai.com/u/curt.kennedy)\
**Post date:** [February 10, 2024, 9:08pm UTC](https://community.openai.com/t/openai-python-sdk-lambda-issues/619625/4 "2024-02-10T21:08:56Z")

</div>

I have avoided installing the OpenAI Python SDK as a Lambda Layer, only because everything I do API-wise can be called by installing the `requests` layer. The cosine similarity stuff can be done on my own too without the SDK. I think the only thing you _might_ need the SDK for is streaming.

---

<div class="post-metadata">

**Author:** ![mija](https://avatars.discourse-cdn.com/v4/letter/m/8491ac/32.png) [@mija](https://community.openai.com/u/mija)\
**Post date:** [March 19, 2024, 2:11am UTC](https://community.openai.com/t/openai-python-sdk-lambda-issues/619625/5 "2024-03-19T02:11:50Z")

</div>

I have been trying to fix this issue for days. Your comment made my week. It worked! Thank you!

---

<div class="post-metadata">

**Author:** ![fernando12](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/fernando12/32/147463_2.png) [@fernando12](https://community.openai.com/u/fernando12)\
**Post date:** [April 24, 2024, 1:39am UTC](https://community.openai.com/t/openai-python-sdk-lambda-issues/619625/6 "2024-04-24T01:39:30Z")

</div>

I’ve tried making the layers and running but still no dice. Any step by step or tip would really help.

---

<div class="post-metadata">

**Author:** ![haarish.prakash](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/haarish.prakash/32/358587_2.png) [@haarish.prakash](https://community.openai.com/u/haarish.prakash)\
**Post date:** [May 5, 2024, 7:00pm UTC](https://community.openai.com/t/openai-python-sdk-lambda-issues/619625/7 "2024-05-05T19:00:43Z")

</div>

Thank you very much! Your solution fixed my issue. Could you let me know how you figured out that using “fastapi” would solve this problem?

---

<div class="post-metadata">

**Author:** ![syed.faique](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/syed.faique/32/150907_2.png) [@syed.faique](https://community.openai.com/u/syed.faique)\
**Post date:** [July 4, 2024, 8:27am UTC](https://community.openai.com/t/openai-python-sdk-lambda-issues/619625/8 "2024-07-04T08:27:44Z")

</div>

Hi all,

I’ve created ready to use **AWS Lambda Layer** for the latest version of **openai**. You can find its .zip over my github repo. Also I’ve shared steps to create custom lambda layer for any of your desired openai version.

**Github username** : syedfaiqueali  
**Repo name** : aws-lambda-layer-openai

Thanks!
