neuron-provider-openai
OpenAI provider for the neuron agent blocks ecosystem. Implements the Provider
and EmbeddingProvider traits from neuron-types against the OpenAI Chat
Completions and Embeddings APIs, supporting synchronous completions, server-sent
event (SSE) streaming, and text embeddings.
The default completion model is gpt-4o. The default embedding model is
text-embedding-3-small. The default base URL is https://api.openai.com.
All can be overridden with the builder API. The base_url override also makes
this client usable with Azure OpenAI and compatible third-party endpoints.
Key Types
OpenAi-- client struct with builder methods (new,model,base_url,organization). ImplementsProviderandEmbeddingProviderfromneuron-types.ProviderError-- re-exported error type for provider failures.EmbeddingError-- re-exported error type for embedding failures.EmbeddingRequest,EmbeddingResponse-- re-exported embedding types.StreamHandle-- returned bycomplete_stream, yieldsStreamEventitems as the model generates tokens.
Features
- Full message mapping: text, tool calls, tool results, images.
- Organization header support for multi-org OpenAI accounts.
ToolChoicesupport:Auto,Any,Required,Specific(name).- SSE streaming parsed from raw byte stream with
data: [DONE]sentinel handling. - Usage statistics included in streaming responses via
stream_options. EmbeddingProvidersupport for generating text embeddings with optional dimension control.
Usage
Completions
use OpenAi;
use ;
async
Embeddings
use OpenAi;
use ;
async
Part of neuron
This crate is one block in the neuron
composable agent toolkit. It depends only on neuron-types.
License
Licensed under either of Apache License, Version 2.0 or MIT License at your option.