Skip to Content
DevelopUsing AI Providers

Using AI providers

Golem comes with an extensive set of libraries  for connecting to various AI and AI related third party providers. These libraries are available as regular Rust crates that can be added as dependencies to Rust-based Golem agents. They provide abstractions for various areas, and pluggable implementations for them. This way the actual third party provider can be switched any time without modifying the Golem agent’s code.

The Rust crates described below are Rust-only. TypeScript, Effect TypeScript, Scala, MoonBit, and Go agents can call provider HTTP APIs directly. A third-party client library must work with the guest runtime’s supported HTTP transport; libraries that require native sockets, JVM networking, or native Node.js extensions are not interchangeable with these APIs.

Call a provider directly

These examples send the same non-streaming OpenAI Chat Completions request. Pass apiKey from your agent’s secret configuration, not from a hard-coded string or a public method parameter. Use a model available to your provider account; the examples use gpt-4o-mini. They return the provider’s complete JSON response rather than assuming a particular choice or tool-call shape. Call the helper from an agent method. See HTTP requests for transport details.

async function askProvider(apiKey: string, prompt: string): Promise<unknown> { const response = await fetch("https://api.openai.com/v1/chat/completions", { method: "POST", headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json", }, body: JSON.stringify({ model: "gpt-4o-mini", messages: [{ role: "user", content: prompt }], }), }) const body = await response.text() if (!response.ok) throw new Error(`Provider returned HTTP ${response.status}`) return JSON.parse(body) }

Do not log the authorization header, prompts, or provider response bodies. Set input and response size limits in production. HTTP status failures and invalid JSON need application error handling. Do not automatically retry a failed generation: a lost response does not prove the provider did not process or charge for the request.

Rust provider libraries

The Rust libraries support these areas:

  • Large Language Models (LLM)
  • Graph Databases
  • Search Engines
  • Web Search Engines
  • Speech to Text
  • Video Generation

To use one of these libraries in a Rust agent, add the corresponding core crate and the desired provider crate(s) as dependencies. The golem.yaml files coming from the agent templates include commented-out entries for each possible choice of implementations, so just uncomment the desired ones and provide any necessary configuration (usually in the form of environment variables).

The rest of the page describes these Rust libraries, their implementations, and their core traits (without a full documentation of every type involved).

LLMs

The list of supported LLM providers is the following:

The core trait for LLMs (from the golem-llm crate):

pub trait Guest { type ChatStream: GuestChatStream; /// Make a single call to the LLM. To continue the conversation: /// - append tool responses and new messages to the events and use send again /// - or use the chat-session wrapper, which helps in maintaining the chat events fn send(events: Vec<Event>, config: Config) -> Result<Response, Error>; /// Makes a single call to the LLM and gets back a streaming API /// to receive the response in chunks. fn stream(events: Vec<Event>, config: Config) -> ChatStream; } pub trait GuestChatStream { fn poll_next(&self) -> Option<Vec<Result<StreamEvent, Error>>>; fn get_next(&self) -> Vec<Result<StreamEvent, Error>>; }

Graph Databases

The list of supported graph databases is the following:

The core trait for graph databases (from the golem-graph crate):

/// Connection pub fn connect(config: ConnectionConfig) -> Result<Graph, GraphError>; /// The Transaction resource exposes all CRUD and traversal operations impl Transaction { // === QUERY OPERATIONS === pub fn execute_query(&self, options: &ExecuteQueryOptions) -> Result<QueryExecutionResult, GraphError>; // === TRAVERSAL OPERATIONS === pub fn find_shortest_path(&self, options: &FindShortestPathOptions) -> Result<Option<Path>, GraphError>; pub fn find_all_paths(&self, options: &FindAllPathsOptions) -> Result<Vec<Path>, GraphError>; pub fn get_neighborhood(&self, options: &GetNeighborhoodOptions) -> Result<Subgraph, GraphError>; pub fn path_exists(&self, options: &PathExistsOptions) -> Result<bool, GraphError>; pub fn get_vertices_at_distance(&self, options: &GetVerticesAtDistanceOptions) -> Result<Vec<Vertex>, GraphError>; pub fn get_adjacent_vertices(&self, options: &GetAdjacentVerticesOptions) -> Result<Vec<Vertex>, GraphError>; pub fn get_connected_edges(&self, options: &GetConnectedEdgesOptions) -> Result<Vec<Edge>, GraphError>; // === VERTEX OPERATIONS === pub fn create_vertex(&self, options: &CreateVertexOptions) -> Result<Vertex, GraphError>; pub fn create_vertices(&self, vertices: &[CreateVertexOptions]) -> Result<Vec<Vertex>, GraphError>; pub fn get_vertex(&self, id: &ElementId) -> Result<Option<Vertex>, GraphError>; pub fn update_vertex(&self, options: &UpdateVertexOptions) -> Result<Vertex, GraphError>; pub fn delete_vertex(&self, id: &ElementId, delete_edges: bool) -> Result<(), GraphError>; pub fn find_vertices(&self, options: &FindVerticesOptions) -> Result<Vec<Vertex>, GraphError>; // === EDGE OPERATIONS === pub fn create_edge(&self, options: &CreateEdgeOptions) -> Result<Edge, GraphError>; pub fn create_edges(&self, edges: &[CreateEdgeOptions]) -> Result<Vec<Edge>, GraphError>; pub fn get_edge(&self, id: &ElementId) -> Result<Option<Edge>, GraphError>; pub fn update_edge(&self, options: &UpdateEdgeOptions) -> Result<Edge, GraphError>; pub fn delete_edge(&self, id: &ElementId) -> Result<(), GraphError>; pub fn find_edges(&self, options: &FindEdgesOptions) -> Result<Vec<Edge>, GraphError>; // === TRANSACTION CONTROL === pub fn commit(&self) -> Result<(), GraphError>; pub fn rollback(&self) -> Result<(), GraphError>; pub fn is_active(&self) -> bool; }

Search Engines

The list of supported search engines is the following:

The core trait for search engines (from the golem-search crate):

pub trait Guest { type SearchStream: GuestSearchStream; // Index lifecycle fn create_index(options: CreateIndexOptions) -> Result<(), SearchError>; fn delete_index(name: IndexName) -> Result<(), SearchError>; fn list_indexes() -> Result<Vec<IndexName>, SearchError>; // Document operations fn upsert(index: IndexName, doc: Doc) -> Result<(), SearchError>; fn upsert_many(index: IndexName, docs: Vec<Doc>) -> Result<(), SearchError>; fn delete(index: IndexName, id: DocumentId) -> Result<(), SearchError>; fn delete_many(index: IndexName, ids: Vec<DocumentId>) -> Result<(), SearchError>; fn get(index: IndexName, id: DocumentId) -> Result<Option<Doc>, SearchError>; // Query fn search(index: IndexName, query: SearchQuery) -> Result<SearchResults, SearchError>; fn stream_search(index: IndexName, query: SearchQuery) -> Result<SearchStream, SearchError>; // Schema inspection fn get_schema(index: IndexName) -> Result<Schema, SearchError>; fn update_schema(index: IndexName, schema: Schema) -> Result<(), SearchError>; } pub trait GuestSearchStream { fn get_next(&self) -> Option<Vec<SearchHit>>; fn blocking_get_next(&self) -> Vec<SearchHit>; }

Web Search Engines

The list of supported web search engines is the following:

The core trait for web search engines (from the golem-web-search crate):

pub trait GuestWebSearch { type SearchSession: GuestSearchSession; /// Start a search session, returning a search context fn start_search(params: SearchParams) -> Result<SearchSession, SearchError>; /// One-shot search that returns results immediately (limited result count) fn search_once(params: SearchParams) -> Result<(Vec<SearchResult>, Option<SearchMetadata>), SearchError>; } pub trait GuestSearchSession { /// Get the next page of results fn next_page(&self) -> Result<Vec<SearchResult>, SearchError>; /// Retrieve session metadata (after any query) fn get_metadata(&self) -> Option<SearchMetadata>; }

Speech to Text

The list of supported speech to text providers is the following:

The core trait for speech to text providers (from the golem-stt crate):

pub trait SttTranscriptionGuest { fn transcribe(req: TranscriptionRequest) -> Result<TranscriptionResult, SttError>; fn transcribe_many( requests: Vec<TranscriptionRequest>, ) -> Result<MultiTranscriptionResult, SttError>; }

Video Generation

The list of supported video generation providers is the following:

The core traits for video generation providers (from the golem-video crate):

pub trait VideoGenerationGuest { fn generate(input: MediaInput, config: GenerationConfig) -> Result<String, VideoError>; fn poll(job_id: String) -> Result<VideoResult, VideoError>; fn cancel(job_id: String) -> Result<String, VideoError>; } pub trait LipSyncGuest { fn generate_lip_sync(video: LipSyncVideo, audio: AudioSource) -> Result<String, VideoError>; fn list_voices(language: Option<String>) -> Result<Vec<VoiceInfo>, VideoError>; } pub trait AdvancedGuest { fn extend_video(options: ExtendVideoOptions) -> Result<String, VideoError>; fn upscale_video(input: BaseVideo) -> Result<String, VideoError>; fn generate_video_effects(options: GenerateVideoEffectsOptions) -> Result<String, VideoError>; fn multi_image_generation(options: MultImageGenerationOptions) -> Result<String, VideoError>; }