Home / How-To / OpenAI Assistants API Azure Functions tutorial: Deploy a serverless assistant
OpenAI Assistants API Azure Functions tutorial: Deploy a serverless assistant
You can build a reusable OpenAI assistant with function calling by defining the assistant in Azure OpenAI, adding a JSON‑based function schema, then using Azure Functions’ assistantSkillTrigger binding to run the function code and submit tool outputs, creating a cheap, auto‑scaling endpoint.

What is the OpenAI Assistants API and why host it with Azure Functions?
- The Assistants API lets you create purpose‑built AI agents with instructions, tools, memory and function calling OpenAI Docs.
- Azure OpenAI provides the same API in a managed service, allowing you to select a model deployment and keep data within your Azure tenant.
- Azure Functions offers a serverless compute model that auto‑scales, charges per execution, and integrates directly with the Assistants API via a special assistantSkillTrigger binding Azure Functions binding docs.
- Combining them yields a low‑cost, always‑available chat backend without managing servers.
How do I create and configure an assistant with a function signature?
- Create an Azure OpenAI resource and enable the Assistants feature.
- Open the Assistants tab in Azure OpenAI Studio (or use the SDK) and click New.
- Fill in:
- Add a function tool under *Assistant tools*.
- *Name* – e.g., “Weather Bot”. - *Instructions* – the system prompt that defines the assistant’s role. - *Model* – the deployment name for a supported model (e.g., gpt-4-1106-preview).
{ "type": "function", "function": { "name": "get_weather", "description": "Get the weather for a location", "parameters": { "type": "object", "properties": { "location": {"type": "string", "description": "City name, e.g. Paris"} }, "required": ["location"] } } }
The description guides the model to select the function when needed S2.
- Save the assistant; note the assistant ID for later use.

How do I set up an Azure Functions app that responds to the assistant?
- Create a Function App in the Azure portal (choose a runtime you prefer – Node.js, Python, or.NET).
- In
host.jsonpin the Azure OpenAI extension to a version earlier than 4.60.0 if you need longer support, e.g.:
{ "version": "2.0", "extensionBundle": { "id": "Microsoft.Azure.Functions.ExtensionBundle", "version": "[4.*,4.60.0)" } }
(The extension retires on 20 April 2027) S3.
- Add a function.json that defines the
assistantSkillTriggerbinding:
{ "bindings": [ { "name": "taskDescription", "type": "assistantSkillTrigger", "dataType": "string", "direction": "in", "functionDescription": "Create a new todo task" } ] }
The functionDescription becomes the static prompt the model sees.
- Implement the function code (examples for C#, JavaScript, and Python are provided in the binding docs) S3.
- Deploy the Function App (VS Code, Azure CLI, or GitHub Actions).
How do I implement the function logic and submit tool outputs back to the assistant?
- Write the function that does the real work, e.g., a Python
get_weatherthat calls OpenWeatherMap.
python def get_weather(location): url = f"https://api.openweathermap.org/data/2.5/weather?q={location}&appid={API_KEY}&units=metric" data = requests.get(url).json() desc = data["weather"][0]["description"] temp = data["main"]["temp"] return f"Weather in {location}: {desc}, {temp}°C"
- In the Function handler, receive the tool call payload (the
assistantSkillTriggerprovides the arguments). Execute the real function and collect the output. - Build a tool_outputs list matching each
tool_call_idreturned by the assistant S4:
python tool_outputs = [{"tool_call_id": call["id"], "output": get_weather(call["function"]["arguments"]["location"])}]
- Submit the outputs using the SDK or a REST call:
bash curl https://$RESOURCE.openai.azure.com/openai/threads/$THREAD_ID/runs/$RUN_ID/submit_tool_outputs?api-version=2024-07-01-preview \ -H "api-key: $KEY" -H "Content-Type: application/json" \ -d '{"tool_outputs": [{"tool_call_id": "call_abc", "output": "..."}]}'
After submission the run moves to queued and then completed, and the assistant returns the final user‑facing response S4.
- Verify the conversation by listing messages on the thread.
Next steps – Add memory, vector‑store retrieval, or additional tools to extend the assistant’s capabilities. See the broader Assistants guide for more patterns OpenAI Docs.
What to do if it does not work?
- Check the binding version – the Azure OpenAI extension must be < 4.60.0 for the preview trigger. Update
host.jsonaccordingly. - Validate the function schema – the JSON must contain
type: "function", aname,description, and aparametersobject with required fields. Errors appear in the Assistant’srequires_actionpayload. - Inspect run status – retrieve the run (
GET /threads/{thread_id}/runs/{run_id}) and look forstatus: "requires_action"or anerrorfield. Thelast_error.messageoften points to missing arguments or mismatchedtool_call_id. - Ensure API version alignment – use the same
api-version(e.g.,2024-07-01-preview) for assistant creation, thread runs, and tool‑output submission. - Review logs – Azure Functions logs (via Application Insights or the portal) show the payload received by the trigger. Confirm the
taskDescription(or equivalent) contains the expected JSON. - Re‑run the flow – after fixing schema or version mismatches, recreate the thread/run or retry the
submit_tool_outputscall. - If the problem persists, consult the official troubleshooting sections in the Assistants docs and the Azure Functions binding guide.
Menus and names can change as products update. If a step looks different, check the product's own help page.
Frequently asked questions
Do I need to host the assistant code anywhere else?
No. The assistant definition lives in Azure OpenAI, and the only code you host is the Azure Function that executes the tool; the binding routes calls automatically.
Can I use multiple functions with one assistant?
Yes. Add several function tools to the assistant; the model can propose calls to any of them and you submit each tool's output using its tool_call_id.
Will the function run in the same region as the OpenAI resource?
Place the Function App in the same Azure region as your OpenAI resource to reduce latency and avoid cross‑region data egress.
How is pricing affected?
You pay for the Azure OpenAI model usage (tokens) plus Azure Functions execution time; there are no additional charges for the binding itself.