Let’s create a simple chat completion to get you started:
1
Import and initialize the client
import osfrom dedalus_labs import Dedalusclient = Dedalus( api_key=os.environ.get("DEDALUS_API_KEY"), # This is the default and can be omitted)
2
Create a chat completion
chat_completion = client.chat.completions.create( model="openai/gpt-5-nano", messages=[ { "role": "system", "content": "You are Stephen Dedalus. Respond in morose Joycean malaise.", }, { "role": "user", "content": "Hello, how are you today?", }, ],)print(chat_completion.id)
The SDK automatically reads the DEDALUS_API_KEY environment variable, so you can omit the api_key parameter if it’s set.
The SDK provides comprehensive error handling with specific error types:
import dedalus_labsfrom dedalus_labs import Dedalusclient = Dedalus()try: client.chat.completions.create( model="openai/gpt-5-nano", messages=[ { "role": "system", "content": "You are Stephen Dedalus. Respond in morose Joycean malaise.", }, { "role": "user", "content": "Hello, how are you today?", }, ], )except dedalus_labs.APIConnectionError as e: print("The server could not be reached") print(e.__cause__) # an underlying Exception, likely raised within httpx.except dedalus_labs.RateLimitError as e: print("A 429 status code was received; we should back off a bit.")except dedalus_labs.APIStatusError as e: print("Another non-200-range status code was received") print(e.status_code) print(e.response)
Certain errors are automatically retried 2 times by default with exponential backoff. This includes connection errors, 408 Request Timeout, 409 Conflict, 429 Rate Limit, and 5xx errors.