# How should I solve this problem when writing code to integrate AI?

**URL:** <https://forum.dynamobim.com/t/how-should-i-solve-this-problem-when-writing-code-to-integrate-ai/115168>\
**Category:** AI\
**Tags:** python\
**Created:** [September 1, 2026, 8:12pm UTC](https://forum.dynamobim.com/t/how-should-i-solve-this-problem-when-writing-code-to-integrate-ai/115168 "2026-09-01T20:12:15Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![CeciliaWan](https://avatars.discourse-cdn.com/v4/letter/c/0ea827/32.png) [@CeciliaWan](https://forum.dynamobim.com/u/CeciliaWan)\
**Post date:** [September 1, 2026, 8:12pm UTC](https://forum.dynamobim.com/t/how-should-i-solve-this-problem-when-writing-code-to-integrate-ai/115168/1 "2026-09-01T20:12:15Z")

</div>

![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/b/4/b4e77ae225aeadbbee96a282a4e26b98766c8c7b.png)

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/b/d/bd3d1776b54de6d4b7dae30ce6fc3fac009f564f.png)

**I checked that the openai module is already installed in my local Python**

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [September 1, 2026, 8:16pm UTC](https://forum.dynamobim.com/t/how-should-i-solve-this-problem-when-writing-code-to-integrate-ai/115168/2 "2026-09-01T20:16:34Z")

</div>

Look into this: [https://github.com/DynamoDS/Dynamo/wiki/Customizing-Dynamo’s-Python-3-installation](https://github.com/DynamoDS/Dynamo/wiki/Customizing-Dynamo's-Python-3-installation)

But before you go about building the tool you are looking into, confirm there is a valid use case for your LLM use. LLM tokens costs can add up quickly, and if you’re looking to automate via Dynamo then using the LLM to produce repeatable code is likely a better use of your funds.

---

<div class="post-metadata">

**Author:** ![Andrew\_Hannell](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/andrew_hannell/32/103315_2.png) [@Andrew\_Hannell](https://forum.dynamobim.com/u/Andrew_Hannell)\
**Post date:** [September 2, 2026, 2:03am UTC](https://forum.dynamobim.com/t/how-should-i-solve-this-problem-when-writing-code-to-integrate-ai/115168/3 "2026-09-02T02:03:36Z")

</div>

It depends what you need to do.

The big AI providers would have you think anything AI has to be one of their LLMs- which is not necessarily the case.

As @jacob.small says- the solution might be simpler than you think. There are also a huge number of AI/machine learning models that can run locally, tailored to a specific purpose

---

<div class="post-metadata">

**Author:** ![c.poupin](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/c.poupin/32/89152_2.png) [@c.poupin](https://forum.dynamobim.com/u/c.poupin)\
**Post date:** [September 2, 2026, 9:56am UTC](https://forum.dynamobim.com/t/how-should-i-solve-this-problem-when-writing-code-to-integrate-ai/115168/4 "2026-09-02T09:56:23Z")

</div>

Hi,

If they are simple requests, you can use urllib (builtin lib) with curl

example

```python
# Load the Python Standard and DesignScript Libraries
import sys
import os 
import json
import urllib.request
import urllib.error
import json
import ssl

apikey = os.getenv("API_KEY_OPENAI")

def translate_AI(text="maison", source="french", target="english"):
    global model_input
    messages = []
    #
    prompt = "Translate the following word from {0} to {1}: {2}. Return the result in JSON format.".format(source, target, text)
    #
    messages.append({"role": "user", "content": prompt})
    # add a prompt system if necessary
    #messages.append({"role": "system", "content": self._history})
    response_data = {}
    url = "https://api.openai.com/v1/chat/completions"
    #
    payload = {
    "model": model_input, 
    "max_completion_tokens": 3000 ,
    "temperature": 1,
    "response_format": { "type": "json_object" },
    "messages": messages,
    "reasoning_effort": "medium", 
    "verbosity": "medium"
    }
    
    # Convert to JSON and encode
    json_data = json.dumps(payload).encode('utf-8')
    
    # Create request with headers
    request = urllib.request.Request(
        url,
        data=json_data,
        headers={
            "Authorization": "Bearer {}".format(apikey),
            "Content-Type": "application/json"
        },
        method='POST'
    )
    
    try:
        # Send request
        with urllib.request.urlopen(request) as response:
            status_code = response.getcode()
            response_data = json.loads(response.read().decode('utf-8'))
    #
    except urllib.error.HTTPError as e:
        print(f"Status Code: {e.code}")
        try:
            error_data = json.loads(e.read().decode('utf-8'))
            print(f"Response: {error_data}")
        except:
            print(f"Response: Error {e.code} - {e.reason}")
    #
    except Exception as e:
        print(f"Error: {e}")
        
    return response_data

model_input = "gpt-5.6-sol" # or IN[0]
# Example 
data_dict = {
"word_to_translate" : "maison",
"lang_source" : "french",
"lang_target" : "english"
}

resultB = translate_AI(data_dict["word_to_translate"], data_dict["lang_source"], data_dict["lang_target"])

result_dict = json.loads(resultB["choices"][0]["message"]["content"])

OUT = data_dict | result_dict

```

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/d/6/d6b83c567d7d0ad5e34130b47f0d9bbc0accde21.png)

---

<div class="post-metadata">

**Author:** ![CeciliaWan](https://avatars.discourse-cdn.com/v4/letter/c/0ea827/32.png) [@CeciliaWan](https://forum.dynamobim.com/u/CeciliaWan)\
**Post date:** [September 2, 2026, 10:23am UTC](https://forum.dynamobim.com/t/how-should-i-solve-this-problem-when-writing-code-to-integrate-ai/115168/5 "2026-09-02T10:23:30Z")

</div>

I used _Anaconda_ to create the python 3.912 environment and installed the openai in this env.

---

<div class="post-metadata">

**Author:** ![CeciliaWan](https://avatars.discourse-cdn.com/v4/letter/c/0ea827/32.png) [@CeciliaWan](https://forum.dynamobim.com/u/CeciliaWan)\
**Post date:** [September 2, 2026, 10:28am UTC](https://forum.dynamobim.com/t/how-should-i-solve-this-problem-when-writing-code-to-integrate-ai/115168/6 "2026-09-02T10:28:47Z")

</div>

Thank you very much,I created my first AI dynamo node.

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/3/2/327ba6fe5a77dc701a51fc90fce894ca834b33cb.jpeg)

---

<div class="post-metadata">

**Author:** ![c.poupin](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/c.poupin/32/89152_2.png) [@c.poupin](https://forum.dynamobim.com/u/c.poupin)\
**Post date:** [September 2, 2026, 10:32am UTC](https://forum.dynamobim.com/t/how-should-i-solve-this-problem-when-writing-code-to-integrate-ai/115168/7 "2026-09-02T10:32:01Z")

</div>

Dynamo is isolated from Anaconda virtual environments. Although it is possible to link a Conda environment via `sys.path`, it is often simpler to install modules directly into Dynamo’s own Python environment (see the Jacob’ s link).
