How to use code interpreter tool with completions API?

I 'm able to use the code interpreter tool with the Assistant API:
all_tools = [
{ “type”: “code_interpreter” },
{ “type”: “function”, “function”: my_function},
]

assistant = client.beta.assistants.create(
name = assistant_name,
instructions=prompt,
model=model,
tools=[{ “type”: “code_interpreter” },
{ “type”: “function”, “function”: my_function},
],
)

How can I pass the code interpreter tool to the completions API? Something like this generates an error:

data = { “model”: model, “messages”: history, “tools”: all_tools }
requests.post(openai_url, json=data, headers=headers)

Error: Missing required parameter: tools[0].function

1 Like

Did you find an answer?
Google Gemini allows you to use code execution on the same endpoint (generateContent), I thought OpenAI also had this functionality. But it seems that it is separate from what I’ve seen so far.