
# Call Tools in Parallel

Some language models support calling tools in parallel.
This is particularly useful when multiple tools are independent of each other and can be executed in parallel during the same generation step.

```ts
import { generateText, tool } from 'ai';
import { openai } from '@ai-sdk/openai';
import { z } from 'zod';

const result = await generateText({
  model: openai('gpt-4-turbo'),
  tools: {
    weather: tool({
      description: 'Get the weather in a location',
      parameters: z.object({
        location: z.string().describe('The location to get the weather for'),
      }),
      execute: async ({ location }: { location: string }) => ({
        location,
        temperature: 72 + Math.floor(Math.random() * 21) - 10,
      }),
    }),
    cityAttractions: tool({
      parameters: z.object({ city: z.string() }),
      execute: async ({ city }: { city: string }) => {
        if (city === 'San Francisco') {
          return {
            attractions: [
              'Golden Gate Bridge',
              'Alcatraz Island',
              "Fisherman's Wharf",
            ],
          };
        } else {
          return { attractions: [] };
        }
      },
    }),
  },
  prompt:
    'What is the weather in San Francisco and what attractions should I visit?',
});

console.log(result);
```


## Navigation

- [Generate Text](/v4/cookbook/node/generate-text)
- [Retrieval Augmented Generation](/v4/cookbook/node/retrieval-augmented-generation)
- [Generate Text with Chat Prompt](/v4/cookbook/node/generate-text-with-chat-prompt)
- [Generate Text with Image Prompt](/v4/cookbook/node/generate-text-with-image-prompt)
- [Stream Text](/v4/cookbook/node/stream-text)
- [Stream Text with Chat Prompt](/v4/cookbook/node/stream-text-with-chat-prompt)
- [Stream Text with Image Prompt](/v4/cookbook/node/stream-text-with-image-prompt)
- [Stream Text with File Prompt](/v4/cookbook/node/stream-text-with-file-prompt)
- [Generate Object with a Reasoning Model](/v4/cookbook/node/generate-object-reasoning)
- [Generate Object](/v4/cookbook/node/generate-object)
- [Stream Object](/v4/cookbook/node/stream-object)
- [Stream Object with Image Prompt](/v4/cookbook/node/stream-object-with-image-prompt)
- [Record Token Usage After Streaming Object](/v4/cookbook/node/stream-object-record-token-usage)
- [Record Final Object after Streaming Object](/v4/cookbook/node/stream-object-record-final-object)
- [Call Tools](/v4/cookbook/node/call-tools)
- [Call Tools in Parallel](/v4/cookbook/node/call-tools-in-parallel)
- [Call Tools with Image Prompt](/v4/cookbook/node/call-tools-with-image-prompt)
- [Call Tools in Multiple Steps](/v4/cookbook/node/call-tools-multiple-steps)
- [Model Context Protocol (MCP) Tools](/v4/cookbook/node/mcp-tools)
- [Web Search Agent](/v4/cookbook/node/web-search-agent)
- [Embed Text](/v4/cookbook/node/embed-text)
- [Embed Text in Batch](/v4/cookbook/node/embed-text-batch)
- [Intercepting Fetch Requests](/v4/cookbook/node/intercept-fetch-requests)
- [Local Caching Middleware](/v4/cookbook/node/local-caching-middleware)


[Full Sitemap](/sitemap.md)
