# Get\_llm\_response( ) function

**URL:** <https://community.deeplearning.ai/t/get-llm-response-function/747802>\
**Category:** AI Python for Beginners\
**Tags:** week-module-3\
**Created:** [January 7, 2025, 3:27pm UTC](https://community.deeplearning.ai/t/get-llm-response-function/747802 "2025-01-07T15:27:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hayou](https://avatars.discourse-cdn.com/v4/letter/h/e0b2c6/32.png) [@hayou](https://community.deeplearning.ai/u/hayou)\
**Post date:** [January 7, 2025, 3:27pm UTC](https://community.deeplearning.ai/t/get-llm-response-function/747802/1 "2025-01-07T15:27:55Z")

</div>

Whenever I try to run the code get\_llm\_response( prompt), I start noticing this error at the end of module 2 and the debut of module 3:  
\*\*---------------------------------------------------------------------------  
PermissionDeniedError Traceback (most recent call last)  
Cell In[2], line 11  
5 prompt = f"“”  
6 Create a short recipe that uses the following ingredients:  
7 {ingredients}  
8 “”"  
10 # Get the response from the LLM  
—\> 11 response = get\_llm\_response(prompt)  
13 # Print the LLM response  
14 print(response)

File ~/work/L1/helper\_functions.py:66, in get\_llm\_response(prompt)  
61 def get\_llm\_response(prompt):  
62 “”“This function takes as input a prompt, which must be a string enclosed in quotation marks,  
63 and passes it to OpenAI’s GPT3.5 model. The function then saves the response of the model as  
64 a string.  
65 “””  
—\> 66 completion = client.chat.completions.create(  
67 model=“gpt-4o-mini”,  
68 messages=[  
69 {  
70 “role”: “system”,  
71 “content”: “You are a helpful but terse AI assistant who gets straight to the point.”,  
72 },  
73 {“role”: “user”, “content”: prompt},  
74 ],  
75 temperature=0.0,  
76 )  
77 response = completion.choices[0].message.content  
78 return response

File /usr/local/lib/python3.9/site-packages/openai/\_utils/\_utils.py:277, in required\_args..inner..wrapper(\*args, \*\*kwargs)  
275 msg = f"Missing required argument: {quote(missing[0])}"  
276 raise TypeError(msg)  
 → 277 return func(\*args, \*\*kwargs)

File /usr/local/lib/python3.9/site-packages/openai/resources/chat/completions.py:590, in Completions.create(self, messages, model, frequency\_penalty, function\_call, functions, logit\_bias, logprobs, max\_tokens, n, presence\_penalty, response\_format, seed, stop, stream, stream\_options, temperature, tool\_choice, tools, top\_logprobs, top\_p, user, extra\_headers, extra\_query, extra\_body, timeout)  
558 @required\_args([“messages”, “model”], [“messages”, “model”, “stream”])  
559 def create(  
560 self,  
(…)  
588 timeout: float | httpx.Timeout | None | NotGiven = NOT\_GIVEN,  
589 ) → ChatCompletion | Stream[ChatCompletionChunk]:  
 → 590 return self.\_post(  
591 “/chat/completions”,  
592 body=maybe\_transform(  
593 {  
594 “messages”: messages,  
595 “model”: model,  
596 “frequency\_penalty”: frequency\_penalty,  
597 “function\_call”: function\_call,  
598 “functions”: functions,  
599 “logit\_bias”: logit\_bias,  
600 “logprobs”: logprobs,  
601 “max\_tokens”: max\_tokens,  
602 “n”: n,  
603 “presence\_penalty”: presence\_penalty,  
604 “response\_format”: response\_format,  
605 “seed”: seed,  
606 “stop”: stop,  
607 “stream”: stream,  
608 “stream\_options”: stream\_options,  
609 “temperature”: temperature,  
610 “tool\_choice”: tool\_choice,  
611 “tools”: tools,  
612 “top\_logprobs”: top\_logprobs,  
613 “top\_p”: top\_p,  
614 “user”: user,  
615 },  
616 completion\_create\_params.CompletionCreateParams,  
617 ),  
618 options=make\_request\_options(  
619 extra\_headers=extra\_headers, extra\_query=extra\_query, extra\_body=extra\_body, timeout=timeout  
620 ),  
621 cast\_to=ChatCompletion,  
622 stream=stream or False,  
623 stream\_cls=Stream[ChatCompletionChunk],  
624 )

File /usr/local/lib/python3.9/site-packages/openai/\_base\_client.py:1240, in SyncAPIClient.post(self, path, cast\_to, body, options, files, stream, stream\_cls)  
1226 def post(  
1227 self,  
1228 path: str,  
(…)  
1235 stream\_cls: type[\_StreamT] | None = None,  
1236 ) → ResponseT | \_StreamT:  
1237 opts = FinalRequestOptions.construct(  
1238 method=“post”, url=path, json\_data=body, files=to\_httpx\_files(files), \*\*options  
1239 )  
 → 1240 return cast(ResponseT, self.request(cast\_to, opts, stream=stream, stream\_cls=stream\_cls))

File /usr/local/lib/python3.9/site-packages/openai/\_base\_client.py:921, in SyncAPIClient.request(self, cast\_to, options, remaining\_retries, stream, stream\_cls)  
912 def request(  
913 self,  
914 cast\_to: Type[ResponseT],  
(…)  
919 stream\_cls: type[\_StreamT] | None = None,  
920 ) → ResponseT | \_StreamT:  
 → 921 return self.\_request(  
922 cast\_to=cast\_to,  
923 options=options,  
924 stream=stream,  
925 stream\_cls=stream\_cls,  
926 remaining\_retries=remaining\_retries,  
927 )

File /usr/local/lib/python3.9/site-packages/openai/\_base\_client.py:1020, in SyncAPIClient.\_request(self, cast\_to, options, remaining\_retries, stream, stream\_cls)  
1017 err.response.read()  
1019 log.debug(“Re-raising status error”)  
 → 1020 raise self.\_make\_status\_error\_from\_response(err.response) from None  
1022 return self.\_process\_response(  
1023 cast\_to=cast\_to,  
1024 options=options,  
(…)  
1027 stream\_cls=stream\_cls,  
1028 )

PermissionDeniedError: Error code: 403 - {‘error’: {‘message’: ‘Project proj\_OXEC08aO6rKYJweAEj6Aae5D does not have access to model gpt-4o-mini’, ‘type’: ‘invalid\_request\_error’, ‘param’: None, ‘code’: ‘model\_not\_found’}}\*\*

---

<div class="post-metadata">

**Author:** ![Mubsi](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/mubsi/32/94983_2.png) [@Mubsi](https://community.deeplearning.ai/u/Mubsi)\
**Post date:** [January 7, 2025, 4:00pm UTC](https://community.deeplearning.ai/t/get-llm-response-function/747802/2 "2025-01-07T16:00:26Z")

</div>

Hi @hayou,

We have recently been aware of this issue.

Please follow this [thread](https://community.deeplearning.ai/t/cannot-use-chat-or-run-any-exercise-that-involves-print-get-llm-response/747776/6) for an update on this.

Thanks,  
Mubsi

---

<div class="post-metadata">

**Author:** ![Mubsi](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/mubsi/32/94983_2.png) [@Mubsi](https://community.deeplearning.ai/u/Mubsi)\
**Post date:** [January 9, 2025, 4:28pm UTC](https://community.deeplearning.ai/t/get-llm-response-function/747802/3 "2025-01-09T16:28:19Z")

</div>


