Function Documentation
  • Developer Platform
    • Overview
    • Service Descriptions
    • First Party Library Support
      • Python Example
      • Typescript & Node Backend Example
    • OpenAI Compatible API
  • Supported Models
    • Chat & Code Completion
    • Embeddings
    • Text To Image
    • Transcription
  • Consumer Demos
    • Function Chat
Powered by GitBook
On this page
  • Step 1: Create a virtual environment
  • Step 2: Add required dependencies
  • Step 3: Create the API Client
  • Step 4: Make an API call
  1. Developer Platform
  2. First Party Library Support

Python Example

PreviousFirst Party Library SupportNextTypescript & Node Backend Example

Last updated 6 months ago

See our full reference implementation .

Note: This page assumes you are using MacOS or Linux. See the reference implementation for Windows instructions.

Step 1: Create a virtual environment

python3 -m venv venv
source venv/bin/activate

# Add Buf registry to virtual environment
printf "
[global]
extra-index-url = https://buf.build/gen/python
" > venv/pip.conf

Step 2: Add required dependencies

pip install fxnlabs-api-gateway-community-danielgtaylor-betterproto
pip install grpclib

Step 3: Create the API Client

api_key = 'MY_FXN_API_KEY'

channel = Channel('api.function.network')
client = APIGatewayServiceStub(channel, metadata=[('authorization', f'Bearer {api_key}')])

Step 4: Make an API call

async def main():
    # Create a text embedding
    response = await client.embed(
        model='baai/bge-small-en-v1.5',
        input='Embed me so I can use it for RAG Pipelines',
    )

    print(response)


if __name__ == "__main__":
    asyncio.run(main())
here