Latest AI news

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.

By AI Decodes Editorial  ·  Published  ·  Last verified 1 December 2026

Diagram showing Azure OpenAI Assistants API connected to an Azure Functions serverless endpoint
Azure OpenAI assistants can trigger Azure Functions for custom tool execution.

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?

  1. Create an Azure OpenAI resource and enable the Assistants feature.
  2. Open the Assistants tab in Azure OpenAI Studio (or use the SDK) and click New.
  3. Fill in:
  4. - *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).

  5. Add a function tool under *Assistant tools*.

{ "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.

  1. Save the assistant; note the assistant ID for later use.
Example JSON schema for a get_weather function and corresponding Python code
Define the function schema in the assistant and implement the logic in a Function.

How do I set up an Azure Functions app that responds to the assistant?

  1. Create a Function App in the Azure portal (choose a runtime you prefer – Node.js, Python, or.NET).
  2. In host.json pin 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.

  1. Add a function.json that defines the assistantSkillTrigger binding:

{ "bindings": [ { "name": "taskDescription", "type": "assistantSkillTrigger", "dataType": "string", "direction": "in", "functionDescription": "Create a new todo task" } ] }

The functionDescription becomes the static prompt the model sees.

  1. Implement the function code (examples for C#, JavaScript, and Python are provided in the binding docs) S3.
  2. 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?

  1. Write the function that does the real work, e.g., a Python get_weather that calls OpenWeatherMap.
  2. 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"

  1. In the Function handler, receive the tool call payload (the assistantSkillTrigger provides the arguments). Execute the real function and collect the output.
  2. Build a tool_outputs list matching each tool_call_id returned by the assistant S4:
  3. python tool_outputs = [{"tool_call_id": call["id"], "output": get_weather(call["function"]["arguments"]["location"])}]

  1. Submit the outputs using the SDK or a REST call:
  2. 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.

  1. 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?

  1. Check the binding version – the Azure OpenAI extension must be < 4.60.0 for the preview trigger. Update host.json accordingly.
  2. Validate the function schema – the JSON must contain type: "function", a name, description, and a parameters object with required fields. Errors appear in the Assistant’s requires_action payload.
  3. Inspect run status – retrieve the run (GET /threads/{thread_id}/runs/{run_id}) and look for status: "requires_action" or an error field. The last_error.message often points to missing arguments or mismatched tool_call_id.
  4. Ensure API version alignment – use the same api-version (e.g., 2024-07-01-preview) for assistant creation, thread runs, and tool‑output submission.
  5. 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.
  6. Re‑run the flow – after fixing schema or version mismatches, recreate the thread/run or retry the submit_tool_outputs call.
  7. 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.