AI

The AI API provides developers with seamless access to AI functionality without requiring API keys, configuration, or extra dependencies.

Some users might not have access to this API. If a user doesn't have access to Raycast AI, they will be asked if they want to get access when your extension calls the AI API. If the user doesn't wish to get access, the API call will throw an error.

You can check if a user has access to the API using environment.canAccess(AI).

API Reference

AI.ask

Ask AI anything you want. Use this in “no-view” Commands, effects, or callbacks. In a React component, you might want to use the useAI util hook instead.

Signature

async function ask(prompt: string, options?: AskOptions): Promise<string> & EventEmitter;

Example

import { AI, Clipboard } from "@raycast/api";

export default async function command() {
  const answer = await AI.ask("Suggest 5 jazz songs");

  await Clipboard.copy(answer);
}

Parameters

NameDescriptionType

prompt*

string

options

Return

A Promise that resolves with a prompt completion.

Types

AI.Creativity

Concrete tasks, such as fixing grammar, require less creativity while open-ended questions, such as generating ideas, require more.

type Creativity = "none" | "low" | "medium" | "high" | "maximum" | number;

If a number is passed, it needs to be in the range 0-2. For larger values, 2 will be used. For lower values, 0 will be used.

AI.Model

The AI model to use to answer to the prompt. Defaults to "openai-gpt-3.5-turbo-instruct".

type Model =
  | "anthropic-claude-haiku"
  | "anthropic-claude-opus"
  | "anthropic-claude-sonnet"
  | "openai-gpt-3.5-turbo-instruct"
  | "openai-gpt-3.5-turbo"
  | "openai-gpt-4"
  | "openai-gpt-4-turbo"
  | "perplexity-sonar-medium-online"
  | "perplexity-sonar-small-online"
  | "llama2-70b"
  | "codellama-70b-instruct"
  | "mixtral-8x7b";

If a model isn't available to the user, Raycast will fallback to a similar one:

  • "anthropic-claude-opus" and "anthropic-claude-sonnet" -> "anthropic-claude-haiku"

  • "openai-gpt-4" and "openai-gpt-4-turbo" -> "openai-gpt-3.5-turbo"

  • "perplexity-sonar-medium-online" -> "perplexity-sonar-small-online"

AI.AskOptions

Properties

PropertyDescriptionType

creativity

Concrete tasks, such as fixing grammar, require less creativity while open-ended questions, such as generating ideas, require more. If a number is passed, it needs to be in the range 0-2. For larger values, 2 will be used. For lower values, 0 will be used.

model

The AI model to use to answer to the prompt.

signal

Abort signal to cancel the request.

AbortSignal

Last updated